Underscore.js _.isElement函数

scu*_*yxx 0 javascript underscore.js

我一直在寻找underscore.js库函数,我注意到一个函数返回元素是否是一个DOM元素.功能如下.

_.isElement = function(obj) {
    return !!(obj && obj.nodeType == 1);
};
Run Code Online (Sandbox Code Playgroud)

你能告诉我为什么!!要用而不是回来(obj && obj.nodeType == 1).我想知道是否!!增加了任何性能改进.任何的想法...

Roc*_*mat 5

!! 强制结果为布尔值.

null例如,如果你通过,那么&&将返回null.该!!转换,要false.

如果obj是"truthy",你将得到obj.nodeType == 1一个布尔值的结果.