JavaScripture
Contribute via GitHub Feedback

JavaScript Object

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

Object() : Object

Same as new 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:

 

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

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.

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.

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:

 

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

Returns a PropertyDescriptor that describes the propertyName property on obj.

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.

Example:

Run

Results:

 

getPrototypeOf(obj : Object) : Object

Returns the prototype of obj.

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.

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: