angular常用对象处理

angular常用对象处理

1.对象复制:angular. copy()

var a = {x:"123"};
var b = angular. copy(a);
a. x = ”456”;
console. log(b);

2.对象聚合:angular. extend()

var a = {x:"123"};
var b = {xx:"456"}
angular. extend(b,a);
console. log(b);

3.空函数:angular. noop();

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

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

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

var l = {a:"1",b:"2"};
angular.forEach(l,function(v,k){console.log(k+":"+v)});

var arr= ["a","b","c"];
angular.forEach(l,function(v,i,o){console.log(v)});

var context = {t:"xx"};
angular.forEach(arr,function(v,i,o){console.log(this.t)},context);
posted @ 2021-01-11 10:39  午亭爱成长  阅读(174)  评论(0编辑  收藏  举报