openKylin论坛

 找回密码

ng,个人认为好的tip收藏到这里(1) [复制链接]

本帖最后由 lzdkylin 于 2015-12-27 21:49 编辑

一、 angular.copy() or angular.extend() 区别
1. angular.copy(source, destination) : It creates a deep copy of source object or array and assign it to destination where ‘destination’ is optional. By writing deep copy, we mean that a new copy of the referred object is made. For example:
var mySource = {'name' : 'sakshi', 'age' : '24', 'obj' :{'key':'value'}}
var myDest = {}
angular.copy(mySource, myDest);
console.log(myDest);
Output: {'name' : 'sakshi', 'age' : '24', 'obj' :{'key':'value'}}
If we check mySource.obj === myDest.obj, this will give false because both point to different objects. This is called as deep copying.
2. angular.extend(destination, src1, src2 …) : It creates a shallow copy of one or more sources provided and assign them to destination. For example:
var mySource1 = {'name' : 'neha', 'age' : '26', obj2 : {}}
var mySource2 = {'course' : 'MCA'}
var myDest = {}
angular.extend(myDest, mySource1,mySource2)
console.log(myDest);
Output: {name: "neha", age: "26", course: "MCA", obj2: Object}
Now we check mySource1.obj2 === myDest.obj2, this will give true because both point to same reference of object. This is called as shallow copying.
NOTE: angular.copy() is slower than angular.extend()
-----------------------


二、http://www.alexkras.com/11-tips-to-improve-angularjs-performance/#ng-repeat
2.1 单向绑定 ,ng1.3,::
2.2 select ng-options


  



楼主
发表于 2015-12-27 13:57:24
回复

使用道具 举报

openKylin

GMT+8, 2024-4-29 21:20 , Processed in 0.023534 second(s), 17 queries , Gzip On.

Copyright ©2022 openKylin. All Rights Reserved .

ICP No. 15002470-12 Tianjin

快速回复 返回顶部 返回列表