Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
362 views
in Technique[技术] by (71.8m points)

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

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

I've already seen the following code :

Object.prototype.toString.apply(t)  

Question:

Is it the most accurate way of checking the object's type?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

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


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...