Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Does ES5 have a counterpart to __lookupGetter__?

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 __lookupGetter__? Or some way of achieving a similar thing?

like image 334
Domenic Avatar asked Apr 11 '11 15:04

Domenic


1 Answers

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

like image 151
olliej Avatar answered Oct 04 '22 22:10

olliej