codecamp

AngularJS 对象处理

对象复制: 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);


AngularJS 上下文绑定
AngularJS 类型判定
温馨提示
下载编程狮App,免费阅读超1000+编程语言教程
取消
确定
目录

关闭

MIP.setData({ 'pageTheme' : getCookie('pageTheme') || {'day':true, 'night':false}, 'pageFontSize' : getCookie('pageFontSize') || 20 }); MIP.watch('pageTheme', function(newValue){ setCookie('pageTheme', JSON.stringify(newValue)) }); MIP.watch('pageFontSize', function(newValue){ setCookie('pageFontSize', newValue) }); function setCookie(name, value){ var days = 1; var exp = new Date(); exp.setTime(exp.getTime() + days*24*60*60*1000); document.cookie = name + '=' + value + ';expires=' + exp.toUTCString(); } function getCookie(name){ var reg = new RegExp('(^| )' + name + '=([^;]*)(;|$)'); return document.cookie.match(reg) ? JSON.parse(document.cookie.match(reg)[2]) : null; }