I am learning javascript and i came across a doubt. Why is the value of \"this\" undefined in the first example , but prints out correctly in the second.
example 1:<
In the first case, the implicit this object is the global scope. Because there is no myName in the global scope, you get undefined.
this
myName
If you want a free function with the proper this, use bind:
bind
var hello = myNamespace.myObject.sayHello.bind(myNamespace.myObject);