 <p>To understand why it is returning <code>undefined</code> instead of <code>ali</code>, you have to understand <strong>JavaScript binding</strong>.</p> <p>If you are accessing a method through a reference instead of directly through its owner object, as you are doing, the method loses its implicit binding, and <code>this</code> stops referencing its owner object and goes back to its default binding, meaning the global object (or <code>undefined</code> in strict mode).</p> <p>Ultimately, what matters is the manner in which the function is invoked.</p> <p>See below for more information (there are exceptions, but it can be generally summarized as the following):</p> <blockquote> <p><strong><a href="https://github.com/getify/You-Dont-Know-JS/blob/master/this%20%26%20object%20prototypes/ch2.md#determining-this" rel="nofollow">Breakdown from YDKJS: Determining <code>this</code></a></strong></p> <p>Now, we can summarize the rules for determining this from a function call's call-site, in their order of precedence. Ask these questions in this order, and stop when the first rule applies.</p> <ol> <li><p>Is the function called with new (<strong>new binding</strong>)? If so, this is the newly constructed object.</p> <ul> <li>var bar = new foo()</li> </ul></li> <li><p>Is the function called with call or apply (<strong>explicit binding</strong>), even hidden inside a bind hard binding? If so, this is the explicitly specified object.</p> <ul> <li>var bar = foo.call( obj2 )</li> </ul></li> <li><p>Is the function called with a context (<strong>implicit binding</strong>), otherwise known as an owning or containing object? If so, this is that context object.</p> <ul> <li>var bar = obj1.foo()</li> </ul></li> <li><p>Otherwise, default the this (<strong>default binding</strong>). If in strict mode, pick undefined, otherwise pick the global object.</p> <ul> <li>var bar = foo()</li> </ul></li> </ol> </blockquote> <p>Note: In ES6, <code>this</code> is the <strong>lexical <code>this</code></strong> for fat arrow functions <code>=&gt;</code> and with object short hand notation (e.g., <code>sampleMethod() {}</code>), meaning that <code>this</code> takes on the outer context as reference. </p>