Take the 2-minute tour ×

In JavaScript there is the possibility to create getters and setters the following way:

function MyClass(){
 var MyField;
  return MyField;
  MyField = value;

But is there a way to get the Getter or Setter FUNCTION? I think of something like this:

var obj = new MyClass();

I need such a functionality when extending base classes. For example: Class "A" has field "a", Class "B" extends from "A" and also wants to have a field "a". To pass values from the "a"-field of a "B"-object to the "a"-field of a "A"-object I need to get the setter/getter function before overriding them.

Hope you understand what I mean.

Thanks for your help!


Ok I found the functions I wanted. Their names are lookupSetter and lookupGetter

share|improve this question
I would advice against relying on that non-standard syntax. –  ChaosPandion Jan 27 '11 at 23:04
you can add the answer as an answer and select it since you found it for yourself –  zzzzBov Jan 27 '11 at 23:05
add comment

3 Answers

up vote 6 down vote accepted

__lookupGetter__ and __lookupSetter__ are what you're after.

share|improve this answer
add comment

Take a look at lookupGetter.

share|improve this answer
add comment

In Google Chrome lookupGetter/lookupSetter is broken: http://code.google.com/p/chromium/issues/detail?id=13175

share|improve this answer
add comment

Your Answer


