【发布时间】:2016-08-10 18:53:00
【问题描述】:
我在我的项目中的 PhpStorm 中的 JavaScript 文件中看到一个警告,我想做一些事情。我有这样的代码:
function someFunction() {
...
var myArray = [1, 2, 3, ...];
$.each(myArray, function() { someOtherFunction(this); }); //warning on this line
....
}
/**
* @param {Number} value
*/
function someOtherFunction(value) {
...
}
在代码中指出的那一行,PHP 给了我这个警告:
参数类型 someFunction 不能分配给参数类型 Number
我确实理解它的含义以及发出此警告的原因:PhpStorm 无法知道 jQuery 在 .each 循环回调中重新定义了 this 上下文。我的问题是我能做些什么来暗示这种重新定义正在发生,this 在这种情况下到底是什么?
【问题讨论】:
标签: javascript jquery this phpstorm each