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
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] |
- Object
Returns the cloned object.
static decodeObject(data)
data |
Object |
static encodeObject(obj)
obj |
Object |
static extendClass(target, origin)
Copy the methods from origin to taget.
target |
Object | The class to extend |
origin |
Object | The mixin to copy from |
static getClassName(object) → bool
Return the string name of the class.
object |
Object |
- bool
static getObjectClassName(object)
Return the name of the class the object was created from.
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.
object |
Object | |
property |
* |
static hasProperty(object, property) → bool
Does the object have the given property?
object |
Object | The object to check |
property |
String | The name of the property |
- 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); }
constructor |
* | |
parentClass |
* |
- 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.
object |
Object |
- bool
static setDefaultOptions(options, defaults)
Copy a value from defaults to options if it is not defined in options.
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)
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,
v |
String |
- *