Namespace: Objects

Phaser.Utils. Objects

Methods


<static> Clone(obj)

Shallow Object Clone. Will not clone nested objects.

Parameters:
Name Type Description
obj object

the object from which to clone

Since: 3.0.0
Source: src/utils/object/Clone.js (Line 7)
Returns:

a new object with the same properties as the input obj

Type
object

<static> Extend()

This is a slightly modified version of http://api.jquery.com/jQuery.extend/

Since: 3.0.0
Source: src/utils/object/Extend.js (Line 13)
Returns:

The extended object.

Type
object

<static> GetAdvancedValue(source, key, defaultValue)

Retrieves a value from an object. Allows for more advanced selection options, including:

Allowed types:

Implicit { x: 4 }

From function { x: function () }

Randomly pick one element from the array { x: [a, b, c, d, e, f] }

Random integer between min and max: { x: { randInt: [min, max] } }

Random float between min and max: { x: { randFloat: [min, max] } }

Parameters:
Name Type Description
source object

The object to retrieve the value from.

key string

The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (.) - banner.hideBanner would return the value of the hideBanner property from the object stored in the banner property of the source object.

defaultValue *

The value to return if the key isn't found in the source object.

Since: 3.0.0
Source: src/utils/object/GetAdvancedValue.js (Line 10)
Returns:

The value of the requested key.

Type
*

<static> GetFastValue(source, key [, defaultValue])

Finds the key within the top level of the source object, or returns defaultValue

Parameters:
Name Type Argument Description
source object

The object to search

key string

The key for the property on source. Must exist at the top level of the source object (no periods)

defaultValue * <optional>

The default value to use if the key does not exist.

Since: 3.0.0
Source: src/utils/object/GetFastValue.js (Line 7)
Returns:

The value if found; otherwise, defaultValue (null if none provided)

Type
*

<static> GetMinMaxValue(source, key, min, max, defaultValue)

Retrieves and clamps a numerical value from an object.

Parameters:
Name Type Description
source object

The object to retrieve the value from.

key string

The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (.).

min number

The minimum value which can be returned.

max number

The maximum value which can be returned.

defaultValue number

The value to return if the property doesn't exist. It's also constrained to the given bounds.

Since: 3.0.0
Source: src/utils/object/GetMinMaxValue.js (Line 10)
Returns:

The clamped value from the source object.

Type
number

<static> GetValue(source, key, defaultValue)

Retrieves a value from an object.

Parameters:
Name Type Description
source object

The object to retrieve the value from.

key string

The name of the property to retrieve from the object. If a property is nested, the names of its preceding properties should be separated by a dot (.) - banner.hideBanner would return the value of the hideBanner property from the object stored in the banner property of the source object.

defaultValue *

The value to return if the key isn't found in the source object.

Since: 3.0.0
Source: src/utils/object/GetValue.js (Line 11)
Returns:

The value of the requested key.

Type
*

<static> HasAll(source, keys)

Verifies that an object contains all requested keys

Parameters:
Name Type Description
source object

an object on which to check for key existence

keys Array.<string>

an array of keys to ensure the source object contains

Since: 3.0.0
Source: src/utils/object/HasAll.js (Line 7)
Returns:

true if the source object contains all keys, false otherwise.

Type
boolean

<static> HasAny(source, keys)

Verifies that an object contains at least one of the requested keys

Parameters:
Name Type Description
source object

an object on which to check for key existence

keys Array.<string>

an array of keys to search the object for

Since: 3.0.0
Source: src/utils/object/HasAny.js (Line 7)
Returns:

true if the source object contains at least one of the keys, false otherwise

Type
boolean

<static> HasValue(source, key)

Determine whether the source object has a property with the specified key.

Parameters:
Name Type Description
source object

The source object to be checked.

key string

The property to check for within the object

Since: 3.0.0
Source: src/utils/object/HasValue.js (Line 7)
Returns:

true if the provided key exists on the source object, otherwise false.

Type
boolean

<static> IsPlainObject(obj)

This is a slightly modified version of jQuery.isPlainObject. A plain object is an object whose internal class property is [object Object].

Parameters:
Name Type Description
obj object

The object to inspect.

Since: 3.0.0
Source: src/utils/object/IsPlainObject.js (Line 7)
Returns:

true if the object is plain, otherwise false.

Type
boolean

<static> Merge(obj1, obj2)

Creates a new Object using all values from obj1 and obj2. If a value exists in both obj1 and obj2, the value in obj1 is used.

Parameters:
Name Type Description
obj1 object

The first object.

obj2 object

The second object.

Since: 3.0.0
Source: src/utils/object/Merge.js (Line 9)
Returns:

A new object containing the union of obj1's and obj2's properties.

Type
object

<static> MergeRight(obj1, obj2)

Creates a new Object using all values from obj1.

Then scans obj2. If a property is found in obj2 that also exists in obj1, the value from obj2 is used, otherwise the property is skipped.

Parameters:
Name Type Description
obj1 object

The first object to merge.

obj2 object

The second object to merge. Keys from this object which also exist in obj1 will be copied to obj1.

Since: 3.0.0
Source: src/utils/object/MergeRight.js (Line 9)
Returns:

The merged object. obj1 and obj2 are not modified.

Type
object