ng中的ng-function中会有些方法,便于我们进行js代码的编写

关于angular.extend(dst, src);通过从src对象复制所有属性到dst来扩展目标对象dst。你可以指定多个src对象。

注意:angular.extend(....)只是简单的对象之间的相互引用,

经典的demo ;

<!DOCTYPE html>
<html ng-app="extendApp">
<head>
<meta charset="UTF-8">
<title></title>
<script src="http://code.angularjs.org/1.2.3/angular.min.js"></script>
</head>
<body>

<div ng-controller="extendController">

<button ng-click="extend()">点击我!</button>

</div>
</body>
</html>

<script type="text/javascript">
angular.module("extendApp", [])
.controller("extendController", function($scope)
{
$scope.baby =
{
cry : function()
{
console.log("I can only cry!");
}
}

$scope.adult =
{
earn : function()
{
console.log("I can earn money!");
},
lover:
{
love:function()
{
console.log("I love you!");
}
}
}
$scope.human = {}

$scope.hehe = "hehe ";

$scope.extend = function()
{
angular.extend($scope.human, $scope.baby, $scope.adult);
$scope.human.cry();
$scope.human.earn();
// $scope.human 和$scope.adult其实引用的是同一个对象-
$scope.human.lover.love = function()
{
console.log("I hate you!");
}

//这两行都会输出“I hate you !",可怜的adult对象, 他把自己的lover分享给了human! -->
$scope.human.lover.love();
$scope.adult.lover.love();
}
});
</script>

结果:

I can only cry!
  I can earn money!
  I hate you!
  I hate you!

拓展:关于对象,数组的复制,我们可以进一步的了解angular.copy();的使用方法

关于angular.extend的用法的更多相关文章

  1. angular.extend用法实例

      angular.extend:依次将第二个参数及后续的参数的第一层属性(不管是简单属性还是对象)拷贝赋给第一个参数的第一层属性,即如果是对象,则是引用的是同一个对象,并返回第一个参数对象. 实例一 ...

  2. angular.extend()和 angular.copy()的区别

    1.angular.copy angular.copy(source, [destination]);  // source: copy的对象. 可以使任意类型, 包括null和undefined. ...

  3. AngularJs angular.forEach、angular.extend

    angular.forEach 调用迭代器函数取每一项目标的集合,它可以是一个对象或数组.迭代器函数与迭代器(value.key)一起调用,其中值是一个对象属性或数组元素的值,而数组元素是对象属性的关 ...

  4. angular.js 的angular.copy 、 angular.extend 、 angular.merge

    <!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title> ...

  5. angular.extend(dst, src)对象拓展

    angular.extend(dst, src) 作用:对象的拓展 参数:  dst:拓展的对象 src:源对象 返回值:拓展的对象 var dst = {name: 'xxx', country: ...

  6. angular.extend

    function f1() {} var f2 = angular.extend(f1, { active: false, toggle: function() { this.active = !th ...

  7. Angular - - angular.forEach、angular.extend

    angular.forEach 调用迭代器函数取每一项目标的集合,它可以是一个对象或数组.迭代器函数与迭代器(value.key)一起调用,其中值是一个对象属性或数组元素的值,而数组元素是对象属性的关 ...

  8. angular.extend、angular.$watch、angular.bootstrap

    1.angular.extend:依次将第二个参数及后续的参数的第一层属性(不管是简单属性还是对象)拷贝给第一个参数的第一层属性,即如果是对象,则是引用的是同一个对象,并返回第一个参数对象. 直接上代 ...

  9. angular.extend深拷贝(deep copy)

    在用到angular.extend的时候,正好碰到一个对象,是层层嵌套的Array, 结果发现只能extend第一层,查阅官文档,确实不支持deep copy: Note: Keep in mind ...

随机推荐

  1. react 子组件改变父组件状态

    class Father extends Component {     construtor(props){         super(props);         this.state={   ...

  2. 发送垃圾邮件的僵尸网络——药物(多)、赌博、股票债券等广告+钓鱼邮件、恶意下载链接、勒索软件+推广加密货币、垃圾股票、色情网站(带宏的office文件、pdf等附件)

    卡巴斯基实验室<2017年Q2垃圾邮件与网络钓鱼分析报告> 米雪儿 2017-09-07 from:http://www.freebuf.com/articles/network/1465 ...

  3. ping函数

    #!/bin/bash #note:ping monitor set -u #set -x ping_fun() { d_network= echo -n "input the networ ...

  4. 73条日常Linux shell命令汇总

    1.检查远程端口是否对bash开放: echo >/dev/tcp/8.8.8.8/53 && echo "open" 2.让进程转入后台: Ctrl + z ...

  5. poj 1258 Agri-Net 最小生成树 prim算法+heap不完全优化 难度:0

    Agri-Net Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 41230   Accepted: 16810 Descri ...

  6. zoj1654

    题解: 对于每一联通的x,y 检点 然后交叉的连边 然后二分图 代码: #include<cstdio> #include<cstring> #include<cmath ...

  7. 【javascript基础】运算符优先级

    优先级 运算类型 关联性 运算符 1 成员运算符 从左到右 . [] new 从右到左 new 2 函数调用运算符 从左到右 () 3 自增运算符 n/a ++ 自减运算符 n/a -- 4 逻辑非运 ...

  8. jinfo用法说明

    以下几种用法 -flags pid :打印当前VM的参数 -flag <name> pid:打印指定JVM的参数值 -flag [+|-]<name> pid:设置指定JVM参 ...

  9. sed和awk简介

    什么是sed和awk         sed和awk是Linux环境下数据的处理工具,可以完成对数据的增删改查的功能.         sed处理时是以行尾单位的,awk处理数据时以字段为单位. se ...

  10. live555源码分析

    live555源代码下载(VC6工程):http://download.csdn.net/detail/leixiaohua1020/6374387 liveMedia 项目(http://www.l ...