补充

发布时间:2022-06-30 发布网站:脚本宝典
脚本宝典收集整理的这篇文章主要介绍了补充脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
//typeof   instanceof区别
 
使用typeof来检测数据类型 
function test(){}
console.log(typeof 1); // number
console.log(typeof test); // function
console.log(typeof "yunxi"); // string
console.log(typeof undefined); // undefined
typeof 检测数组 
console.log(typeof ]); // object对象
var arr=[1,2,3,4,5];
 //console.log(typeof arr);object
 // console.log(typeof {});object

 Instanceof

instanceof来检测某个对象是否是数组

返回一个布尔型(boolean),如果是数组的话,返回true

console.log(arr instanceof Array);//true
 console.log({} instanceof Object);//true
 console.log(arr instanceof Object);//true
 
 
//call apply    bind函数的拷贝类型的拷贝 为什么
call()、apply()、bind() 都是用来重定义 this 这个对象的
        console.log(Object.prototype.toString.call(arr))
        console.log(Object.prototype.toString.bind(arr)())
bind()函数需再加()才能调用函数

脚本宝典总结

以上是脚本宝典为你收集整理的补充全部内容,希望文章能够帮你解决补充所遇到的问题。

如果觉得脚本宝典网站内容还不错,欢迎将脚本宝典推荐好友。

本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。
标签: