检查JS对象类型的最准确方法是什么? [英] The most accurate way to check JS object's type?
本文介绍了检查JS对象类型的最准确方法是什么?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
typeof
运算符并不能帮助我们找到对象的真实类型。
The typeof
operator doesn't really help us to find the real type of an object.
I已经看过以下代码:
I've already seen the following code :
Object.prototype.toString.apply(t)
问题:
这是大多数检查对象类型的准确方法?
Is it the most accurate way of checking the object's type?
推荐答案
JavaScript规范提供了一种正确的方法来确定对象的类型对象的类:
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
这篇关于检查JS对象类型的最准确方法是什么?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文