JQuery library was developed specifically to simplify and to unify certain JavaScript functionality.(JQuery库是专门为简化和统一某些JavaScript功能而开发的。)
However if you need to check a variable against undefined
value, there is no need to invent any special method, since JavaScript has a typeof
operator, which is simple, fast and cross-platform:(但是,如果需要根据undefined
值检查变量,则无需创建任何特殊方法,因为JavaScript具有typeof
运算符,该运算符简单,快速且跨平台:)
if (typeof value === "undefined") {
// ...
}
It returns a string indicating the type of the variable or other unevaluated operand.(它返回一个字符串,指示变量的类型或其他未评估的操作数。)
The main advantage of this method, compared to if (value === undefined) { ... }
, is that typeof
will never raise an exception in case if variable value
does not exist.(与if (value === undefined) { ... }
相比,此方法的主要优点是,如果变量value
不存在, typeof
将永远不会引发异常。) 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…