Join MDN and developers like you at Mozilla's View Source conference, 12-14 September in Berlin, Germany. Learn more at

Defining Getters and Setters

Misleading example code

The o = new Object; part of the example code is rather misleading as it just creates an object that is discarded by the next statement when a second object is created (Unless I've missed some kind of Ruby-like object extension support in JavaScript 1.5.)

Blixt 01:18, 29 April 2008 (PDT)

Getter/Setter Definition Clarification

Since there were no objections even after a few months of waiting, I've moved the clarifications to the article, under the heading "Summary".

Harald Albrecht 22:10, 06 Dec 2005 (MEZ)

Reserved Words?

Does this mean that 'get' and 'set' are now reserved words? It would be nice to know, since .get() and .set() are commonly used method names. AdmiralNovia 10:49, 11 April 2006 (PDT)

It doesn't seem so. --Nickolay 14:10, 11 April 2006 (PDT)

Available only in C?

I'm pretty new to JavaScript, so this is just a note for wiser heads than mine.

The "What's new" page at the start of this document ( says, "Getters and Setters: JavaScript writers can now add getters and setters to their objects. This feature is available only in the C implementation of JavaScript."

The text here currently says nothing about being available only in C. One location or the other should be clarified.

Not "only in C", but only in SpiderMonkey, the reference JavaScript implementation written in C and used in Mozilla-based products, such as Firefox. I'm not sure which other implementations support this feature, but you're welcome to add a clarification that this is a non-standard (not in ECMA 262 ed 3) feature, supported by at least SpiderMonkey. --Nickolay 16:10, 24 October 2006 (PDT)

Document Tags and Contributors

 Contributors to this page: Blixt, Nickolay, Spooty, AdmiralNovia, Harald Albrecht
 Last updated by: Blixt,