11
获取Javascript变量类型的更好方法?
是否有比JS中更好的方法来获取变量的类型typeof?当您这样做时,它可以正常工作: > typeof 1 "number" > typeof "hello" "string" 但是,当您尝试以下操作时,它是没有用的: > typeof [1,2] "object" >r = new RegExp(/./) /./ > typeof r "function" 我知道instanceof,但这需要您事先知道类型。 > [1,2] instanceof Array true > r instanceof RegExp true 有没有更好的办法?
260
javascript
types
typeof