If I have the following code:
var obj = {
x: 34,
init: function() {
alert(this.x);
alert(obj.x)
}
};
Both al
I would say there are two differences here:
this
can get shadowed. Creating an anonymous function in JavaScript can unfortunately replace this
with a reference to the new anonymous function you're in, and not the current object you want access to.this
is more flexible if the name of the object changes.this
is probably faster in this case because JavaScript won't need to look up the reference.