?self | Object |
fn的上下文对象,使用this调用 |
?fn | function() |
被绑定的function |
?args | * |
传入fn中的参数(可选的) |
?
<!DOCTYPE HTML> <html ng-app> <head> </head> <script src="http://code.angularjs.org/1.2.3/angular.min.js"></script> </body> <script> var self = {name:‘boyi‘}; //示例1--带参数 var f = angular.bind(self, //绑定对象,作为函数的上下文 //被绑定的函数 function(age){ alert(this.name + ‘ is ‘ + age + ‘ !‘); }, //绑定的参数,可省略 ‘15‘ ); f();//调用绑定之后的function //示例2--不带参数 var m = angular.bind(self, //绑定对象,作为函数的上下文 //被绑定的函数 function(age){ alert(this.name + ‘ is ‘ + age + ‘ !‘); } //省略参数 ); m(3);//调用传参的函数 </script> </body> </html>?
原文:http://boyitech.iteye.com/blog/2162297