Using the ECMAScript5 Object.getownpropertydescriptor () method, you can obtain a descriptor for a given property. This method receives two parameters: the object where the property resides and the name of the property whose descriptor you want to read. The return value is an object, and if it is an accessor property, the property of the object has configurable, enumerable, get, and set, and if it is a data property, the object's properties are configurable, enumerable, Writable and value. For example:
var book = {};object.defineproperties (book,{ _year:{ value:2004 }, edition:{ value:1 }, year:{ get:function () { return this._year; }, set:function (newvalue) { if (newvalue> 2004) { this._year = newvalue; This.edition + = newValue-2004;}}} ); var descriptor = object.getownpropertydescriptor (book, "_year"); alert (descriptor.value);//2004alert ( descriptor.configurable);//falsealert (typeof descriptor.get);//"undefined" var descriptor = Object.getownpropertydescriptor (book, ' Year '); alert (descriptor.value);//undefinedalert (descriptor.enumerable); /falsealert (typeof descriptor.get);//"function"
For data Properties _year,value equals the original value, configurable is false, and get equals undefined. For accessor properties Year,value equals undefined,enumerable is false, and get is a pointer to the Getter function.
In JavaScript, you can use the Object.getownpropertydescriptor () method for any object, including Dom and BOM objects. Browsers that support this approach are ie9+, ff4+, safari5+, opera12+, and Chrome.
6.1.3 Properties of Read attributes