CopyCodeThe Code is as follows: 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;
}
// Each logic and operation is enclosed in parentheses in the original text, but brackets can be omitted Based on the operator priority.
// The first line declares undefined. In my personal understanding, to improve performance, you do not have to query undefined in the top-level scope.
As explained in the ECMA-262, object. Prototype. tostring () returns the type of the object instance in the format of "[object", class, and "]" string.
Therefore, slice is used to extract the 'class' value, that is, the type value.
Among them, null and undefined are exceptions, because they return
[Object object] in IE
Standard browser [Object window].
Therefore, let alone make a judgment.
RelatedArticle: Javascript deep copy