开发者

Does ES5 have a counterpart to __lookupGetter__?

开发者 https://www.devze.com 2023-02-24 00:44 出处:网络
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__?

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

0

精彩评论

暂无评论...
验证码 换一张
取 消