Copy Code code as follows:
The var is = function (Obj,type) {
var tostring=object.prototype.tostring,undefined;
return obj===null&&type=== ' null ' | |
obj===undefined&&type=== ' Undefined ' | |
Tostring.call (obj). Slice (8,-1) ===type;
}
The original text has parentheses wrapping each logic and operation, but according to operator precedence, parentheses can be omitted
The first line declares undefined, and personal understanding is to improve performance without having to go to the top-level scope to query undefined.
According to the interpretation in ECMA-262, Object.prototype.toString () returns the type of the object instance, returning the format "[Object", Class, and "]" string.
So the ' class ' value is intercepted by slice, which is the type value.
Where null and undefined are exceptions, because they return the
IE in [Object Object]
Standard Browser [object Window].
So alone come up with judgment.
Related article: JavaScript deep copy