加载中...

对象处理


12.2. 对象处理

对象复制: angular.copy()

  1. var a = {'x': '123'};
  2. var b = angular.copy(a);
  3. a.x = '456';
  4. console.log(b);

对象聚合: angular.extend()

  1. var a = {'x': '123'};
  2. var b = {'xx': '456'};
  3. angular.extend(b, a);
  4. console.log(b);

空函数: angular.noop()

大小写转换: angular.lowercase()angular.uppercase()

JSON转换: angular.fromJson()angular.toJson()

遍历: angular.forEach() ,支持列表和对象:

  1. var l = {a: '1', b: '2'};
  2. angular.forEach(l, function(v, k){console.log(k + ': ' + v)});
  3. var l = ['a', 'b', 'c'];
  4. angular.forEach(l, function(v, i, o){console.log(v)});
  5. var context = {'t': 'xx'};
  6. angular.forEach(l, function(v, i, o){console.log(this.t)}, context);

还没有评论.