underscore源碼地址: https://github.com/jashkenas/... 852行 function factory(name, color) { this.name = name; this.color = color;
}
factory.prototype.init = function() { document.querySelector('.parent').addEventListener('scroll', throttle(function(){ console.log(this.name, this.color)
}, 1000, {leading: false, trailing: true}))
} var product = new factory('jack', 'white')
product.init()滾動(dòng)時(shí),打印的值為 undefined, undefined而源碼中執(zhí)行的時(shí)候,用了apply綁定this的作用域result = func.apply(context, args);但這樣好像并沒(méi)有什么用,所以這里為什么不直接用 func(args)
underscore里面的throttle,執(zhí)行func的時(shí)候?yàn)槭裁匆胊pply綁定
qq_遁去的一_1
2018-08-10 20:14:08