0

I am wondering why JSON.stringify(this.Master.Func) returns 'undefined' instead of function() { ... }.

Function itself executes by adding ().

JSfiddle: http://jsfiddle.net/t4ngY/

CODE

var $ = {}; // some global

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();
Mike
  • 731
  • 9
  • 27

1 Answers1

0

if you want see function text you can simply call toString method like this

console.log(this.Master.Func.toString()); 
Grundy
  • 13,231
  • 3
  • 34
  • 54