Created
May 12, 2011 20:07
-
-
Save jtwb/969335 to your computer and use it in GitHub Desktop.
Javascript getter/setter unified API
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var getOwnPropertyDescriptor = function(obj, property) { | |
if (!obj) return; | |
if (obj.__lookupGetter__) { | |
return { | |
get: obj.__lookupGetter__(property), | |
set: obj.__lookupSetter__(property) | |
}; | |
} else { | |
return Object.getOwnPropertyDescriptor(obj, property); | |
} | |
}; | |
/* | |
* Utility function: setDescriptor - override getters and setters of property | |
*/ | |
var defineProperty = function(obj, property, descriptor) { | |
if (!obj) return; | |
if (obj.__defineGetter__) { | |
descriptor.get && obj.__defineGetter__(property, descriptor.get); | |
descriptor.set && obj.__defineSetter__(property, descriptor.set); | |
} else { | |
Object.defineProperty(obj, property, descriptor); | |
} | |
}; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment