Hi,
I saw Brendan Eich in an online conference video say that in
JavaScript 2 that they will lexically bind the "this" keyword of inner
functions. He said that currently the execution-time resolution of
"this" is considered a bug by some. I often take advantage of the fact
that "this" is resolved during execution. Is JavaScript 2 going to
break all my (our?) code?
For example, one time, to save typing and download time, I automated
the creation of simple getter functions
function capitalize(str) {
return str.charAt(0).t oUpperCase() + str.substr(1);
}
var Attr = {
makeGet: function(constr uctor, prop) {
constructor.pro totype['get'+capitaliz e(prop)] = function() {
return this[prop];
}
}
};
function Person(firstNam e, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
Attr.makeGet(Pe rson, 'firstName', 'lastName');
var ted = new Person('ted', 'nugent')
alert(ted.getFi rstName()); // --'ted'
So if "this" is lexically bound will ted.getFirstNam e() look for a
Attr.makeGet.fi rstName property?
I'm worried. Any ideas out there?
Thanks,
Peter