<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title></title> </head> <body> <h1>angular.bind</h1> <p> <span>使用方法:</span><br /> <span>angular.bind(self, fn, args)</span> </p> <p> <span>参数:</span><br /> <span>self: Object,fn的上下文对象,使用this调用</span><br /> <span>fn: Function,被绑定的fn</span><br /> <span>args:传入fn中的参数(可选)</span> </p> <p> <span>返回值:</span><br /> <span>返回动态绑定之后的函数</span> </p> </body> <script src="../../js/angular.1.3.0.js" type="text/javascript" charset="utf-8"></script> <script type="text/javascript"> var obj = {name: ‘张三‘}; // 带参数 var fn1 = angular.bind(obj, function(age){ console.log(this.name + ‘是‘ + age); }, ‘15岁!‘) fn1(); var fn2 = angular.bind(obj, function(age){ console.log(this.name + ‘是‘ + age); }) fn2(‘18岁了!‘); </script> </html>
原文地址:https://www.cnblogs.com/tanxiang6690/p/9764629.html
时间: 2024-11-09 10:49:59