angular.bind

<!DOCTYPE html>
<html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
        <title>bind例子</title>
        <script type="text/javascript" src="js/angular.min.js" ></script>
        <script type="text/javascript">
        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>
</head>
<body>
</body>
</html>
原文地址:https://www.cnblogs.com/lihfeiblogs/p/5709753.html