bind方法和bindall方法都是用來設定函式的this值的,區別是呼叫方式不同。
var xiaoming =}//bind
var func =bind(xiaoming, xiaoming.say);
func();
//i am xiaoming
//bindall
bindall(xiaoming, 'say');
var func =xiaoming.say;
func();
//i am xiaoming
bind和bindall都是改變函式的this指向,然後返回乙個新的函式,永久的指向這個this指向
舉例
functionperson(name,age)
person.prototype.sayname = function
()person.prototype.sayage = function
()var person = new person('xiaoming',26);
var func =person.sayname;
func();
$('button').click(person.sayage);
無論如何呼叫,sayname和sayperson的this都指向person物件。
underscore 常用的方法
參考文件 collection map 類似array.map 但是返回的是物件 filter 返回陣列,對於nodelist 返回的是document 節點 every 返回boolean 迭代的列表每個都是true才會返回 true some 返回boolean 迭代的列表有乙個為true 就返...
underscore的簡單了解
1.underscore 乙個封裝好的js工具庫,它提供了一整套函式式程式設計的使用功能,但是沒有擴充套件任何js內建物件。它解決了這個問題 如果我面對乙個空白的html,並希望立即開始工作,我需要什麼?2.zip var require underscore 演示 var names 張三 李四 ...
underscore相關記錄
在很多框架的原始碼以及webpack打包出來的bundle.js中,我們都可以看到void 0的身影,如下 function generaterandomkey seenkeys key true return key module.exports function shallowequal obj...