What is “void 0”?
本问题已经有最佳答案,请猛点这里访问。
我正在通过阅读一些代码来学习Javascript,但这个功能真的让我很困惑。
1 2 3 4 5 | hv: function(i) { var _this = this; return isArr(_this) ? _this.indexOf(i) > -1 : _this[i] !== void 0; } |
此功能被添加到
我在三元表达式的末尾没有得到
谢谢。
The void operator is often used merely to obtain the undefined primitive value,
usually using"void(0)" (which is equivalent to"void 0"). In these cases, the
global variable undefined can be used instead (assuming it has not been assigned
to a non-default value).
在这种情况下,可以使用全局变量undefined:
即:
1 | _this[i] !== undefined; |
Jsfiddle演示