angularJs的工具方法1

一、angular.bind();  

  改this指向

<!DOCTYPE HTML>

<html ng-app>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

<script src="angular.min.js"></script>

<script>

    function show(n1,n2){

        alert(n1);

        alert(n2);

        alert(this);

    }

    angular.bind(document,show)(3,4);

    //angular.bind(document,show,3)(4);      //也可以这样传入参数

    

</script>

</head>

<body>



</body>

</html>

 

 

 

二、angular.copy();

  拷贝对象

<!DOCTYPE HTML>

<html ng-app>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

<script src="angular.min.js"></script>

<script>

    var a = {

        name : 'hello'

    };

    var b = {

        age : '20'

    };

    var c = angular.copy(a);   //结果c就是复制了a的对象

    console.log(c);

    var c = angular.copy(a,b);   //写了两个参数,a把所有值覆盖给了b

    console.log(c);

    console.log(b); //b也变成跟a一样

</script>

</head>

<body>

    

</body>

</html>

 

 

 

 

三、angular.extend(); 

  对象继承

<!DOCTYPE HTML>

<html ng-app>

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<title>无标题文档</title>

<script src="angular.min.js"></script>

<script>

    var a = {

        name : 'hello'

    };

    var b = {

        age : '20'

    };



    var c = angular.extend(b,a);   //相当于b继承了a,把a里面的值赋值给b

    console.log(a);

    console.log(b);

    console.log(c);

</script>

</head>

<body>



</body>

</html>

 

你可能感兴趣的:(AngularJS)