Phaser API Documentation

  Version: 
Filter
Namespace: Objects
Phaser.Utils.Objects
Source: src/utils/object/index.js (Line 7)

Methods

<static> Clone(obj)
Focus
Focus

Description:

Shallow Object Clone. Will not clone nested objects.

Parameters:

name type description
obj object

The object to clone.

Returns:
Description:

A new object with the same properties as the input object.

Type:
  • object
Since: 3.0.0
Source: src/utils/object/Clone.js (Line 7)
Focus
Focus
<static> DeepCopy(obj)
Focus
Focus

Description:

Deep Copy the given object or array.

Parameters:

name type description
obj object

The object to deep copy.

Returns:
Description:

A deep copy of the original object.

Type:
  • object
Since: 3.50.0
Focus
Focus
<static> Extend([args])
Focus
Focus

Description:

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

Parameters:

name type arguments description
args * <optional>

The objects that will be mixed.

Returns:
Description:

The extended object.

Type:
  • object
Since: 3.0.0
Focus
Focus
<static> GetAdvancedValue(source, key, defaultValue)
Focus
Focus

Description:

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.

Returns:
Description:

The value of the requested key.

Type:
  • *
Since: 3.0.0
Focus
Focus
<static> GetFastValue(source, key, [defaultValue])
Focus
Focus

Description:

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

Parameters:

name type arguments 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.

Returns:
Description:

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

Type:
  • *
Since: 3.0.0
Focus
Focus
<static> GetMinMaxValue(source, key, min, max, defaultValue)
Focus
Focus

Description:

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.

Returns:
Description:

The clamped value from the source object.

Type:
  • number
Since: 3.0.0
Focus
Focus
<static> GetValue(source, key, defaultValue)
Focus
Focus

Description:

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.

Returns:
Description:

The value of the requested key.

Type:
  • *
Since: 3.0.0
Focus
Focus
<static> HasAll(source, keys)
Focus
Focus

Description:

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

Returns:
Description:

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

Type:
  • boolean
Since: 3.0.0
Source: src/utils/object/HasAll.js (Line 7)
Focus
Focus
<static> HasAny(source, keys)
Focus
Focus

Description:

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

Returns:
Description:

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

Type:
  • boolean
Since: 3.0.0
Source: src/utils/object/HasAny.js (Line 7)
Focus
Focus
<static> HasValue(source, key)
Focus
Focus

Description:

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

Returns:
Description:

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

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> IsPlainObject(obj)
Focus
Focus

Description:

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.

Returns:
Description:

true if the object is plain, otherwise false.

Type:
  • boolean
Since: 3.0.0
Focus
Focus
<static> Merge(obj1, obj2)
Focus
Focus

Description:

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.

This is only a shallow copy. Deeply nested objects are not cloned, so be sure to only use this function on shallow objects.

Parameters:

name type description
obj1 object

The first object.

obj2 object

The second object.

Returns:
Description:

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

Type:
  • object
Since: 3.0.0
Source: src/utils/object/Merge.js (Line 9)
Focus
Focus
<static> MergeRight(obj1, obj2)
Focus
Focus

Description:

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.

Returns:
Description:

The merged object. obj1 and obj2 are not modified.

Type:
  • object
Since: 3.0.0
Focus
Focus
<static> Pick(object, keys)
Focus
Focus

Description:

Returns a new object that only contains the keys that were found on the object provided. If no keys are found, an empty object is returned.

Parameters:

name type description
object object

The object to pick the provided keys from.

keys array

An array of properties to retrieve from the provided object.

Returns:
Description:

A new object that only contains the keys that were found on the provided object. If no keys were found, an empty object will be returned.

Type:
  • object
Since: 3.18.0
Source: src/utils/object/Pick.js (Line 9)
Focus
Focus
<static> SetValue(source, key, value)
Focus
Focus

Description:

Sets a value in an object, allowing for dot notation to control the depth of the property.

For example:

var data = {
  world: {
    position: {
      x: 200,
      y: 100
    }
  }
};

SetValue(data, 'world.position.y', 300);

console.log(data.world.position.y); // 300

Parameters:

name type description
source object

The object to set the value in.

key string

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

value any

The value to set into the property, if found in the source object.

Returns:
Description:

true if the property key was valid and the value was set, otherwise false.

Type:
  • boolean
Since: 3.17.0
Focus
Focus