我有一个对象,我从中调用一个函数。而不是它返回函数本身的值。这可能是重复的,但我找不到合适的解决方案。所以任何关于这个问题的流行词都会受到高度赞赏。JavaScript返回函数不值
var w = window,
d = document,
e = d.documentElement,
g = d.getElementsByTagName('body')[0];
var asd = {
getWindowWidth: function() {
var x = w.innerWidth || e.clientWidth || g.clientWidth;
return x;
},
getWindowHeight: function() {
var x = (function() {
return w.innerWidth || e.clientWidth || g.clientWidth;
})();
return x;
},
init: function() {
console.log("init fired");
console.log(this.getWindowWidth);
console.log(this.getWindowHeight);
console.log(typeof(this.getWindowHeight));
}
}
asd.init();
预先感谢您对我们的支持。
嘛'的console.log(this.getWindowWidth);'返回函数' console.log(this.getWindowWidth());'评估它并返回结果,如果这就是你问的(这不是很清楚)。 –
“我有一个我称之为函数的对象” - 不,你不知道。你有一个从你console.log一个函数的对象。你必须在指向函数的指针之后加上'()'来实际调用它。 – Quentin