Gets the own property descriptor of the specified object. An own property descriptor is one that is defined directly on the object and is not inherited from the object’s prototype.
SyntaxObject.getOwnPropertyDescriptor( object , propertyname )
The descriptor of the property.
ExamplesThe following example gets a data property descriptor and uses it to make the property read-only.
var obj = {};
obj.newDataProperty = "abc";
var descriptor = Object.getOwnPropertyDescriptor(obj, "newDataProperty");
descriptor.writable = false;
Object.defineProperty(obj, "newDataProperty", descriptor);
To list the property attributes, you can add the following code to this example.
var desc2 = Object.getOwnPropertyDescriptor(obj, "newDataProperty");
for (var prop in desc2) {
document.write(prop + ': ' + desc2[prop]);
document.write("<br />");
}
Remarks
You can use the Object.getOwnPropertyDescriptor function to obtain a descriptor object that describes attributes of the property.
The Object.defineProperty Function is used to add or modify properties.
See also Other articles AttributionsMicrosoft Developer Network: Article
RetroSearch is an open source project built by @garambo | Open a GitHub Issue
Search and Browse the WWW like it's 1997 | Search results from DuckDuckGo
HTML:
3.2
| Encoding:
UTF-8
| Version:
0.7.4