为什么这可能是未定义的,我该如何解决?
var a = 1;
var b = 1 + function(){ return 10; }// This could be the wrong way to do it. But it could come from a third party, so it's undeterminded when it's returning. S
console.log(b);
答案 0 :(得分:0)
如果你想让这个功能起作用,你必须执行它:
var a = 1;
var b = 1 + function(){ return 10; }()// This could be the wrong way to do it. But it could come from a third party, so it's undeterminded when it's returning. S
console.log(b);
注意我在函数后添加了()。
答案 1 :(得分:0)
您必须调用该函数。
var a = 1;
var b = 1 + (function(){ return 10; })()
console.log(b);