angular方法
1. bind
绑定对象,作为函数的上下文
<script>
var self={name:'张三'};
var f=angular.bind(self,function(age){
$scope.info=this.name+' is '+age;
console.log($scope.info);
});
f(30);//张三 is 30
var f=angular.bind(self,function(age){
$scope.info=this.name+' is '+age;
console.log($scope.info);
},10);
f();//张三 is 10
</script>
2. forEach
对象或数组的迭代函数
var json = {"name":"hello","age":"20","sex":'男'};
angular.forEach(json,function(val,key){
console.log(val);//hello 20 男
console.log(key);//name age sex
});
var results=[];
angular.forEach(json,function(val,key){
this.push(key+'--'+val);
},results);
console.log(results);// ["name--hello", "age--20", "sex--男"]
3. copy
数组或对象深度拷贝
$scope.a={name:'张三'};
$scope.b={age:10};
$scope.c=angular.copy($scope.a,$scope.b);
console.log($scope.a);//{name:'张三'}
console.log($scope.b);//{name:'张三'}
4. formJson
反序列化,将字符串转换成json对象
var json = '{"name":"hello","age":"20"}';
console.log(json);//{"name":"hello","age":"20"} 字符串
$scope.json=angular.fromJson(json);
console.log($scope.json);//对象
5. toJson
序列化,将json对象转换成字符串
var json = {"name":"hello","age":"20"};
console.log(json);//json对象
$scope.json=angular.toJson(json);
console.log($scope.json);//json字符串
6. extend
继承
$scope.a={name:'张三'};
$scope.b={age:10};
$scope.c=angular.extend($scope.b,$scope.a);
console.log($scope.b);//{age: 10, name: "张三"}
7. 比较
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。