Testing 'this' of function inside object.

by makzan

HTML

<p>Run it and there are 3 console logs.</p>
<p>The 1st one indicate the 'this' inside sayHi method is person object.</p>
<p>The 2nd one indicate the 'this' inside greeting function is window.</p>

JavaScript

var person = {
    nickname: "Makzan",
    sayHi: function() {
        console.log(this);
        var greeting = function() {
            console.log(this);
            return "Aloha " + this.nickname;
        }
        console.log(greeting());
    }
}
person.sayHi();