ObjectUtil

Utility functions related to Javascript Objects.

Constructor

new L3D.ObjectUtil()

Methods

static cloneObject(object, target, recursive, onlyExisting, encodeObjects) → nullable Object

Clone an object, recursively. Only allows objects containing numbers, strings, typed arrays, and other objects.

  • It skips attributes starting with "_", "@", or "jQuery", and functions.
  • It tries to see which is the best copy to perform
Parameters
object Object

The object to clone

target Object

the destination object. If null, a new object is

recursive bool

if you want to encode objects recursively.

onlyExisting bool

only assign to methods existing in the target

encodeObjects bool

if a special object is found, encode it as ["@ENC",node,object]

Returns
Object

Returns the cloned object.

static decodeObject(data)

Parameters
data Object

static encodeObject(obj)

Parameters
obj Object

static extendClass(target, origin)

Copy the methods from origin to taget.

Parameters
target Object

The class to extend

origin Object

The mixin to copy from

static getClassName(object) → bool

Return the string name of the class.

Parameters
object Object
Returns
bool

static getObjectClassName(object)

Return the name of the class the object was created from.

Parameters
object Object

static getPropertyDescriptor(object, property)

Find a property descriptor of a property on an object, even if the property was defined by an ancestor class.

Parameters
object Object
property *

static hasProperty(object, property) → bool

Does the object have the given property?

Parameters
object Object

The object to check

property String

The name of the property

Returns
bool

static instanceOf(constructor, parentClass) → bool

This is a bit more robust than standard Javascript instanceof as it can handle constructor functions. For example, the following wouldn't work with instanceof: import * as assets from "./assets/index.js", for (let i in assets) { ObjectUtil.instanceOf(assets[i], Asset); }

Parameters
constructor *
parentClass *
Returns
bool

static isEmpty(object) → bool

Checks if the object is empty, meaning it's null, an Object with no properties, or an empty array or string.

Parameters
object Object
Returns
bool

static setDefaultOptions(options, defaults)

Copy a value from defaults to options if it is not defined in options.

Parameters
options Object
defaults Object

static setEnumerable(classObject, properties, enumerable)

Defines a set of properties as being enumerable or not for a class. Enumberable properties will show up when you do things like for (const property in object)

Parameters
classObject class
properties *

String or Array of strings for the properties to set

enumerable bool true

Whether the properties should be considered enumerable or not

static stringToValue(v) → *

Convert the string to a value, which can be a Number or Object,

Parameters
v String
Returns
*