[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
~~~