Does ES5 have an __lookupGetter__ analogue?

I know that Object.defineProperty is a lot of fun and a great replacement for the non-standard APIs __defineGetter__ and __defineSetter__ , but is there a similar instance for __lookupGetter__ ? Or some way to achieve such a thing?

+6
source share
1 answer

I'm not sure about the semantics of __lookupGetter__ , but ES5 provides a new API Object.getOwnPropertyDescriptor that gives you a descriptor object containing property attributes and either its value or its get and / or set .

eg.

 Object.getOwnPropertyDescriptor("foo", {get foo() { return 5} }).get 

Gives you a getter function

+8
source

Source: https://habr.com/ru/post/885665/


All Articles