Brendan Eich interview

M

Martin Honnen

Ben said:
Where could one look online for an explanation of what some of this
stuff actually is and how it would work (getters and setters, strict
mode, built-in JSON)?

JSON:
https://developer.mozilla.org/En/Using_JSON_in_Firefox
http://msdn.microsoft.com/en-us/library/cc836458(VS.85).aspx

Mozilla's JavaScript implementation has had getters and setters for
quite a while
(https://developer.mozilla.org/en/Co...ting_New_Objects/Defining_Getters_and_Setters)
although I haven't checked whether that is the same syntax as in the
latest attempt to finally agree on a new ECMAScript edition.

IE 8 has getters/setters for DOM stuff
(http://msdn.microsoft.com/en-us/library/dd229916(VS.85).aspx) and that
article claims "Internet Explorer 8 is the first browser to adopt the
ECMAScript 3.1 syntax for defining accessor properties", again I have
not checked whether the syntax is the same as in the latest attempt to
agree on a new ECMAScript edition (where 3.1 has been pimped to 5).
 
R

RobG

JSON:https://developer.mozilla.org/En/Us...rosoft.com/en-us/library/cc836458(VS.85).aspx

Mozilla's JavaScript implementation has had getters and setters for
quite a while
(https://developer.mozilla.org/en/Core_JavaScript_1.5_Guide/Creating_N...)
although I haven't checked whether that is the same syntax as in the
latest attempt to finally agree on a new ECMAScript edition.

If they become widely implemented, will they just be another language
feature to abuse?

It might be convenient to have a getter where a value must be
calcuated, e.g element.getHeight() might become element.height, but
it also seems that things that really should look like methods may
become getters or setters that don't look like they are methods, e.g.
if you have an array-like object with a calcuated key for new
properties, e.g.

Current way (though I would probably use the module pattern to keep
prefix and lastIndex private):

var obj = {
prefix: 'key_',
lastIndex: 0,
getNewKey: function() {
this.lastIndex++;
return this.prefix + this.lastIndex;
}
}

// Get a key
var newKey = obj.getNewKey();
alert(newKey);


Using getter:

var obj = {
prefix: 'key_',
lastIndex: 0,
get newKey() {
this.lastIndex++;
return this.prefix + this.lastIndex;
}
}

// Get a key
var newKey1 = obj.newKey;


To me, the first is preferable as it is obvious that a function is
being called and therefore something is being calculated, even if
'get' is not included in the name, whereas in the second it is not.
It isn't clear that accessing newKey will neceesarily return a new
value each time or do any calculation (call a method) at all.

Anyhow, do getters and setters really add anything useful, or are they
just new ways to obfuscate code? Would it be better to allow programs
to set readOnly properties and hence force the use of a set function
at least?

IE 8 has getters/setters for DOM stuff
(http://msdn.microsoft.com/en-us/library/dd229916(VS.85).aspx) and that
article claims "Internet Explorer 8 is the first browser to adopt the
ECMAScript 3.1 syntax for defining accessor properties", again I have
not checked whether the syntax is the same as in the latest attempt to
agree on a new ECMAScript edition (where 3.1 has been pimped to 5).

I think that might be an incorrect use of "pimp", though I may not be
hip enough to US slang to know for sure. If they want to be cool, why
not be way ahead of the curve and call it "five-point-oh". :)
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,022
Latest member
MaybelleMa

Latest Threads

Top