What is “this”?
You may have noticed something slightly strange in our methods. Look at this one for example:
greeting: function() { alert('Hi! I\'m ' + this.name.first + '.'); }
You are probably wondering what “this” is. The this
keyword refers to the current object the code is being written inside — so in this case this
is equivalent to person
.