Reputation: 25
Why does Javascript return the baz method as 'typeof function' instead of its result and how can I output the result instead?
var someObject = new Object();
someObject.foo = $('#someElement'),
someObject.bar = $('#someOtherElement'),
someObject.baz = function() {
return 'Hello world!';
}
console.log(someObject.baz); // Outputs: function (){return"Hello world!"}
Eventually I want to let baz calculate the height difference of the elements in foo and bar but so far I haven't been able to access the calculated result in baz or any other result like the string in the code example above.
Upvotes: 1
Views: 67
Reputation: 4785
Because it is holding a reference to the function. If you want to return the result then you have to execute it
ex: someObject.baz()
Upvotes: 1