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;
}
//In the original text, there are parentheses surrounding each logical AND operation, but according to the operator priority, the parentheses can be omitted
// The first line declares undefined. My personal understanding is to improve performance and avoid querying undefined in the top-level scope.
According to the explanation in ECMA-262, Object.prototype.toString() , will return the type of object instance and return a string in the format "[object ", class, and "]".
So intercept the 'class' value through slice, which is the type value.
The exceptions are null and undefined, because they return
[object Object] in IE
Standard browser [object Window].
So make a separate judgment.
Related articles:
javascript deep copy Statement:The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn