typeof在检测基本类型时非常好用:
typeof null ===> object
instanceof在检测引用类型时非常好用:
alert(person instanceof Object) ====> //变量person 是 Object 吗? true
alert(person instanceof Array) ====> //变量person 是 Array吗? true
alert(person instanceof RegExp) ====> //变量person 是 RegExp吗? true
(注:在IE和FireFox中,对正则表达式应用typeof会返回“object”。其他浏览器返回“function”。)
js:typeof与instanceof的区别
最新推荐文章于 2024-02-29 00:00:00 发布