"xxx : this.yyy" in prototype

Aymeric Vitte vitteaymeric at gmail.com
Wed Feb 15 10:21:29 PST 2012

I did not find any related subject in discussions or specs so here it is :

var f=function(name) {

     get nodeName() {return this._name},
     get tagName() {return this._name},
     get anotherNameInvention() {return this._name},
     set nodeName() {},
     set tagName() {},
     set anotherNameInvention() {},

So in that case we have to define several getters and setters for 
something that is refering to the same object, slowing down the overall 
script execution, it would probably be better to have something like :

     nodeName <operator> this._name,
     tagName <operator> this._name,
     anotherNameInvention <operator> this._name

var g=new f('test') --> g.nodeName is equal to g._name

While calling new the <operator> would indicate that g.nodeName must be 
equal to g._name whether _name is a property or a method.

nodeName, tagName, etc could be defined in f but this does not solve the 
case if we want them to be inherited properties.

Maybe no <operator> is required and the default behavior should be the 
one described above (what could be the use of declaring something like 
xxx : this.yyy in prototype ??? I have never seen it).

Example of use : js w3c dom implementation where objects own a lot of 
redundant properties.


A. Vitte

Email :  avitte at jcore.fr
Web :    www.jcore.fr
Webble : www.webble.it
Extract Widget Mobile : www.extractwidget.com
BlimpMe! : www.blimpme.com

More information about the es-discuss mailing list