JavaScripture
Contribute via GitHub Feedback

Reflect : Object

Provides methods to inspect and interact with objects programmatically. Similar to pre-ECMAScript 2015 methods on Object and Function.

Reflect Methods

apply(target : Object, thisArg : Object, parameters : Array) : Object

See Function.apply().

Example:

Run

Results:

 

construct(constructor : Function, parameters : Array, [newTarget : Function]) : Object

Essentially the same as new constructor(...parameters). newTarget allows you to change what the new.target value is inside the constructor.

Example:

Run

Results:

 

defineProperty(obj : Object, propertyName : String, propertyDescriptor : PropertyDescriptor) : Boolean

The same as Object.defineProperty() except returns false on failure instead of throwing an exception.

Example:

Run

Results:

 

deleteProperty(obj : Object, propertyName : String) : Boolean

The same as delete object[propertyName]. Returns true if the value was deleted (ie, the property was configurable).

Example:

Run

Results:

 

get(target : Object, propertyName : String, [getterThis : Object]) : Object

The same as target[propertyName]. If propertyName is a get function, target is used as its this if getterThis is not specified.

Example:

Run

Results:

 

getOwnPropertyDescriptor(obj : Object, propertyName : String) : PropertyDescriptor

The same as Object.getOwnPropertyDescriptor() except throws an exception if obj is not an Object.

Example:

Run

Results:

 

getPrototypeOf(obj : Object) : Object

The same as Object.getPrototypeOf() except throws an exception if obj is not an Object.

Example:

Run

Results:

 

has(obj : Object, propertyName : String) : Boolean

Returns true if obj has a property named propertyName. The in operator provides the same result.

Example:

Run

Results:

 

isExtensible(obj : Object) : Boolean

The same as Object.isExtensible() except throws an exception if obj is not an Object.

Example:

Run

Results:

 

ownKeys(obj : Object) : Array<String>

The same as Object.getOwnPropertyNames() except throws an exception if obj is not an Object.

Example:

Run

Results:

 

preventExtensions(obj : Object) : Boolean

The same as Object.preventExtensions() except returns false on failure and throws an exception if obj is not an Object.

Example:

Run

Results:

 

set(target : Object, propertyName : String, value : Object, [setterThis : Object]) : Boolean

The same as target[propertyName] = value. Returns true if the set was successful and false otherwise (if the object was frozen for example). If propertyName is a set function, target is used as its this if setterThis is not specified.

Example:

Run

Results:

 

setPrototypeOf(obj : Object, proto : Object) : Boolean

Changes the prototype of obj to proto.

Example:

Run

Results: