12.2. 对象处理
对象复制: angular.copy()
- var a = {'x': '123'};
var b = angular.copy(a);
a.x = '456';
console.log(b);
对象聚合: angular.extend()
- var a = {'x': '123'};
var b = {'xx': '456'};
angular.extend(b, a);
console.log(b);
空函数: angular.noop()
大小写转换: angular.lowercase() 和 angular.uppercase()
JSON转换: angular.fromJson() 和 angular.toJson()
遍历: angular.forEach() ,支持列表和对象:
- var l = {a: '1', b: '2'};
angular.forEach(l, function(v, k){console.log(k + ': ' + v)});
var l = ['a', 'b', 'c'];
angular.forEach(l, function(v, i, o){console.log(v)});
var context = {'t': 'xx'};
angular.forEach(l, function(v, i, o){console.log(this.t)}, context);