The most accurate way to check JS object's type?

后端 未结 9 1016
借酒劲吻你
借酒劲吻你 2020-12-04 05:33

The typeof operator doesn\'t really help us to find the real type of an object.

I\'ve already seen the following code :

Object.prototyp         


        
9条回答
  •  执笔经年
    2020-12-04 05:48

    The JavaScript specification gives exactly one proper way to determine the class of an object:

    Object.prototype.toString.call(t);
    

    http://bonsaiden.github.com/JavaScript-Garden/#types

提交回复
热议问题