A question spurred by curiosity, if I have the following code, what’s the benefit (beyond just the simplicity) of calling a property via this instead of user in the show_name method?
var user = {
name : 'John Doe',
show_name : function(){
alert(this.name);
// OR
alert(user.name);
}
};
The difference becomes obvious, if you have a look at this example. It creates a second object and sets the prototype accordingly.
Here
this.namerefers to the current object’snameproperty, whereasuser.namealways refers to the originalnameproperty.