JavaScript Object.defineProperties()
Example
Add properties:
// Create an Object:
const person = {
firstName: "John",
lastName: "Doe"
};
// Add Properties
Object.defineProperties(person, {
language: {value: "en"},
year: {value: "Hello"}
});
Try it Yourself »
Description
The Object.defineProperties()
method adds or changes object properties.
The Object.defineProperties()
method lets you change property metadata.
The Object.defineProperties()
method lets you add getters and setters.
See more example below.
Related Methods:
Object.defineProperty() adds or changes one property.
Object.defineProperties() adds or changes many properties.
Object.getOwnPropertyNames() returns the property names of an object.
Object.getOwnPropertyDescriptor() returns the descriptor of a property.
Object.getOwnPropertyDescriptors() returns the descriptors of all properties.
Syntax
Object.defineProperty(object , property, descriptor)
Parameters
Parameter | Description |
object | Required. The object. |
object | Required. The property name. |
descriptor | Required. A descriptor of the properties to be added or changed: value: value writable : true|false enumerable : true|false configurable : true|false get : function set : function |
Return Value
Type | Description |
Object | The object beeing passed, with the changes made. |
Browser Support
Object.defineProperties()
is an ECMAScript5 (ES5) feature.
ES5 (JavaScript 2009) is fully supported in all modern browsers since July 2013:
Chrome 23 |
IE/Edge 11 |
Firefox 21 |
Safari 6 |
Opera 15 |
Sep 2012 | Sep 2012 | Apr 2013 | Jul 2012 | Jul 2013 |