JS中每個Function對象都有一個apply()方法和一個call()方法
apply 丰刊、call 則是立即調(diào)用
func.call(this, arg1, arg2)
func.apply(this, [arg1, arg2])
arguments 是對象,類數(shù)組瞒斩,其實不是數(shù)組
bind方法
bind 是返回對應函數(shù)破婆,便于稍后調(diào)用
Function.prototype.bind = function(ctx) {
var arg = Array.prototype.slice.apply(arguments, 1)
var self = this
return function(){
var arg1 = Array.prototype.slice.apply(arguments)
return self.apply(ctx, arg.concat(arg1))
}
}