JavaScripture
Contribute via GitHub Feedback

Object

Object is the base in the prototype chain. JavaScript Objects can have any number values stored as properties (specified by String names or Symbols).

Object() : Object
Object(value : Object) : Object

Constructors

new Object() : Object

Creates an empty object. Can also be constructed as {}.

Example:

Run

Results:

 

new Object(value : Object) : Object

If value is a primitive type, creates a box for value. Otherwise, returns value.

Example:

Run

Results:

 

Instance Indexers

this[propertyName : String] : Object

Returns the value stored in this at the specified propertyName. This is the same as the . style access but also allows the property name to be specified at runtime using a String of being hardcoded and allows access to properties that are invalid identifiers (such as including spaces or starting with a number).

Example:

Run

Results:

 

this[symbol : Symbol] : Object

Returns the value stored in this at the specified symbol.

Example:

Run

Results:

 

Instance Methods

constructor : Function

The Function that constructed this.

Example:

Run

Results:

 

hasOwnProperty(propertyName : String) : Boolean

Returns true if this has a property named propertyName stored on it. This method can be used to see if a property is set on the object, even if the value is set to undefined. Properties stored in the prototype chain do not count.

Example:

Run

Results:

 

isPrototypeOf(obj : Object) : Boolean

Returns true if this is in the prototype chain of obj.

Example:

Run

Results:

 

propertyIsEnumerable(propertyName : String) : Boolean

Returns true if the property named propertyName on this is enumerable and should be returned during a for (x in y) loop.

Example:

Run

Results:

 

toLocaleString() : String

Returns a locale specific (if possible) string representation of this.

Example:

Run

Results:

 

toString() : String

Returns a string representation of this. This method is called each time the object is used in a place a string is expected. Define your own toString to give a better string representation to your objects.

Example:

Run

Results:

 

valueOf() : Object

For boxed primitive types, returns the unboxed value.

Example:

Run

Results:

 

Object Methods

assign(target : Object, source1 : Object, [source2 : Object, [...]]) : Object

Copies properties from each source to target. Any properties already set on target are overwritten. Returns target.

Example:

Run

Results:

 

create(prototype : Object, [propertyDescriptors : Object]) : Object

Returns a new Object with prototype equal to prototype. Pass null for prototype to create an object with no prototype. Calls defineProperties(obj, propertyDescriptors) with the new object if propertyDescriptors is specified.

Example:

Run

Results:

 

defineProperties(obj : Object, propertyDescriptors : Object) : Object

For each property on propertyDescriptors, defines a new property on obj with the same name and supplied PropertyDescriptor. Returns obj. See also getOwnPropertyDescriptors().

Example:

Run

Results:

 

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

Defines a new property with name equal to propertyName on obj with the supplied descriptor. Returns obj. See Reflect.defineProperty().

Example:

Run

Results:

 

entries(obj : Object) : Array<Array>

Returns an Array of key/value pairs for the properies of obj. See also fromEntries(), keys(), and values().

Example:

Run

Results:

 

freeze(obj : Object) : Object

For each property on obj, sets its PropertyDescriptor.configurable property to false and PropertyDescriptor.writable property to false. Also calls preventExtensions on obj. Returns obj.

Example:

Run

Results:

 

fromEntries(keyValuePairs : Iterator<Array>) : Object

Constructs a new Object from the specified key-value pairs. See also entries().

Example:

Run

Results:

 

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

Returns a PropertyDescriptor that describes the propertyName property on obj.

Example:

Run

Results:

 

getOwnPropertyDescriptors(obj : Object) : PropertyDescriptor

Returns an object key-value pairs of the property name and PropertyDescriptors that describes obj. See also getOwnPropertyDescriptor and create() and defineProperties().

Example:

Run

Results:

 

getOwnPropertyNames(obj : Object) : Array<String>

Returns an Array of the names of all properties set on obj including those that are not enumerable. See also keys().

Example:

Run

Results:

 

getOwnPropertySymbols(obj : Object) : Array<Symbol>

Returns an Array of the symbols of properties set on obj including those that are not enumerable.

Example:

Run

Results:

 

getPrototypeOf(obj : Object) : Object

Returns the prototype of obj.

Example:

Run

Results:

 

is(obj1 : Object, obj2 : Object) : Boolean

Returns true if obj1 is identical to obj2. This is mostly the same as obj1 === obj2 except for some Number comparisons involving NaN, 0, and -0.

Example:

Run

Results:

 

isExtensible(obj : Object) : Boolean

Returns false if preventExtensions was called on obj. A non-extensible object cannot have new properties added to it.

Example:

Run

Results:

 

isFrozen(obj : Object) : Boolean

Returns true if freeze was called on obj. A frozen object cannot have new properties added and existing properties cannot be modified.

Example:

Run

Results:

 

isSealed(obj : Object) : Boolean

Returns true if seal was called on obj. A sealed object cannot have new properties added to it but the value of existing properties can be changed.

Example:

Run

Results:

 

keys(obj : Object) : Array<String>

Returns an Array containing the enumerable properties on obj. See also getOwnPropertyNames(), entries() and values().

Example:

Run

Results:

 

preventExtensions(obj : Object) : Object

Prevents new properties from being added to obj. Unlike freeze, existing properties can be modified. Returns obj.

Example:

Run

Results:

 

seal(obj : Object) : Object

Same as preventExtensions except it also sets each property as not configurable. Returns obj.

Example:

Run

Results:

 

setPrototypeOf(obj : Object, prototype : Object) : Object

Changes the prototype of obj to prototype. Returns obj.

Example:

Run

Results:

 

values(obj : Object) : Array<Object>

Returns an Array containing the enumerable property values on obj. See also entries() and keys().

Example:

Run

Results: