IntelliJ IDEA中js代码报如下警告的解决方法

IntelliJ IDEA使用教程 (总目录篇)



IntelliJ IDEA中js代码报如下警告:

Possible iteration over unexpected (custom / inherited) members, probably missing hasOwnProperty check

Checks for any instances of unfiltered for-in loops in JavaScript. The use of this construct results in processing inherited or unexpected properties. You need to filter own properties with hasOwnProperty() method. The validation works in JavaScript, html or jsp files.


报警告的代码如下:

		//后面的就是个循环对象
		for(i in widgetArr){
			if(widgetArr[i] != null){
				updateWidgetMenu(widgetArr[i], id, M0DULE_TYPE_DASHBOARD, isEditDashboard);
			}
		}

修改后如下:

		for(var i in widgetArr){
			if(widgetArr.hasOwnProperty(i)){
				if(widgetArr[i] != null){
					updateWidgetMenu(widgetArr[i], id, M0DULE_TYPE_DASHBOARD, isEditDashboard);
				}
			}
		}

区别在于:widgetArr. hasOwnProperty(i)


做了个这个判断。


你可能感兴趣的:(intellij,idea)