Can someone explain why JSON.stringify(this.Master.Func)
is showing 'undefined' instead of function() { ... }
?
The function executes when we add ()
.
Check out the JSfiddle demo here: http://jsfiddle.net/t4ngY/
CODE
var $ = {}; // declaring a global variable
var Master =
{
property: 'Property',
Func: function()
{
console.log('I am Func inside Master');
},
PassToGlobal: function()
{
$.master = this;
}
};
Master.PassToGlobal();
var Slave =
{
Master: $.master,
ShowFunc: function()
{
console.log(JSON.stringify(this.Master.Func)); //returns undef
this.Master.Func(); //prints `I am Func inside Master`
}
}
Slave.ShowFunc();