Javascript 为什么我的函数没有得到';这个.arg';
我写了下面的代码,但正如预期的那样,它的值应该是4,但它给出的是未定义的。我不明白为什么Javascript 为什么我的函数没有得到';这个.arg';,javascript,function,this,Javascript,Function,This,我写了下面的代码,但正如预期的那样,它的值应该是4,但它给出的是未定义的。我不明白为什么 function outputInteger (a) { console.log(this.a); } outputInteger(4); 预期结果:4 给定结果:未定义 提前感谢。您只需参考参数a的名称即可: function outputInteger (a) { console.log(a); } outputInteger(4); 的可能重复此与函数是对象这一事实无关。问题在于,“正常”函数
function outputInteger (a) {
console.log(this.a);
}
outputInteger(4);
预期结果:4
给定结果:未定义
提前感谢。您只需参考参数a的名称即可:
function outputInteger (a) {
console.log(a);
}
outputInteger(4);
的可能重复此
与函数是对象这一事实无关。问题在于,“正常”函数调用中的这个是没有意义的。在严格模式下,OP的代码实际上会抛出一个错误。