I know Object.defineProperty
is lots of fun and a great replacement for __defineGetter__
and __defineSetter__
nonstandard APIs, but is there a similar counterpart for __l开发者_JAVA技巧ookupGetter__
? Or some way of achieving a similar thing?
I'm not sure of the __lookupGetter__
semantics but ES5 provides a new API Object.getOwnPropertyDescriptor
that gives you a descriptor object containing the attributes of a property and either its value
or its get
and/or set
functions.
eg.
Object.getOwnPropertyDescriptor("foo", {get foo() { return 5} }).get
Will give you the getter function
精彩评论