Article Directory
typeof
typeof is an operator that the right side with a monadic expression, and returns the data type of the expression. The results returned are represented by the type of string (all lowercase letters) in the form of
typeof although can be used, but if you use it to view or null type of the array, will be overturned oh
because typeof only return number, boolean, string, undefined , object, function, ES as well as symbol
Object.prototype.toString…
toString () is the prototype Object methods that, when invoked, return the current default object [[Class]]. For Object object, direct call toString () can return [object Object], while for other objects, you need to call in order to return the correct type information call.
Object.prototype.toString.call(arr/obj)
Returns a string directly show what type of correspondence, no pressure, is perfect
since .call so that, then I tried it and bind apply, the discovery Ye Hao. Rest assured!
Object.prototype.toString.apply(arr/obj)
Object.prototype.toString.bind(arr/obj)()
instanceof
A instanceof determines whether to Example B, the expression is: A instanceof B, if A is Example B, then returns true, otherwise returns false. instanceof prototype testing, whether there is an internal mechanism by determining the type of the object prototype prototype chain.
This is very sad, very useless.
- Because the return value is a Boolean value. You can only rely on their own guess, and then test yourself is not a type. Or Object.prototype.toString.xxx easy to use, direct people to return string, to see more intuitive and accurate.
- Because it can not determine the basic data types, you see all six basic data types overturned.
If you ask me why I do not writec instanceof null
d instanceof undefined
, because writing so will complain!
constructor
When a function is defined, JS Prototype prototype engine to add, and then adding a constructor property on the prototype. Constructor property points to the function itself.
This is super invincible tasteless , null and undefined direct encounters an error
, but fortunately, other data types can judge
I am a Luo Lian, today is the day it hard