多应用+插件架构,代码干净,二开方便,首家独创一键云编译技术,文档视频完善,免费商用码云13.8K 广告
[TOC] ## 1、判断js中的数据类型的方法 > 最少有几种方法:typeof、instanceof、 constructor、 prototype、$.type()/jquery.type() 更具体的解释再链接里[链接](https://www.cnblogs.com/dushao/p/5999563.html) > var a = "string" > var c= [1,2,3]; ``` 1.最常见的判断方法:typeof alert(typeof a) 2、判断已知对象类型的方法: instanceof alert(c instanceof Array) 3、根据对象的constructor判断: constructor alert(c.constructor === Array) 4、通用但很繁琐的方法: prototype alert(Object.prototype.toString.call(a) === ‘[object String]’) 5、无敌万能的方法:jquery.type() jQuery.type( "test" ) === "string" ``` ##3、 jquery 中如何将数组转化为json字符串,然后再转化回来? ``` JSON.stringify(array) 字符串转成数组 JSON.parse(array) ``` ## 4、JQuery一个对象可以同时绑定多个事件,这是如何实现的? ``` * 多个事件同一个函数: $("div").on("click mouseover", function(){}); * 多个事件不同函数 $("div").on({ click: function(){}, mouseover: function(){} }); ``` ## 5.bind,apply,call的作用,及apply和call的区别 ~~~ 作用:改变函数内部的this指向 apply,call的区别:apply和call的功能是一样的,只是传入的参数列表形式不同 apply:最多只能有两个参数call:它可以接受多个参数 ~~~ ### bind 改变函数执行的上下文环境 返回对应函数,便于稍后调用 ~~~ var name = "li"; var ding = {   name:"ding" }         var test = function(){           console.log(this.name) }.bind(ding); test(); ~~~ ### apply+call 直接执行函数。 ~~~ var ding = {   name:"ding" } var li = {   name:"li",   sayName(a,b){       console.log(this.name)       console.log(a+b);   } } li.sayName.call(ding,1,2);       // ding 3 li.sayName.apply(ding,[1,3]);   //ding 4 ~~~