javascript - how to find the set/get functions of a property (Object.defineProperty) -
suppose property defined follows:
object.defineproperty(window, 'prop', { set: setval, get: getval, configurable: true }) ;
what redefine window.prop, example:
var ref2setval = window.prop.set ; var ref2getval = window.prop.get ; object.defineproperty(window, 'prop', { set: function(val){ ref2setval(val*2); }, get: function() { return 10 + ref2getval(); } }) ;
window.prop.set/get not work, possible ?
object.getownpropertydescriptor
standards compliant way:
var desc = object.getownpropertydescriptor(window, "prop"); var ref2setval = desc.set; var ref2getval = desc.get;
Comments
Post a Comment