标签:
返回值:this指向self的新函数
var obj = { name: ‘xxx‘, print: function (country) { console.log(this.name + ‘ is form ‘ + country); } }; var self = { name: ‘yyy‘ }; var bindFn = angular.bind(self, obj.print, ‘China‘); //var bindFn = angular.bind(self, obj.print, [‘China‘]); obj.print(‘American‘); //$ xxx is form American bindFn(); //$ yyy is form China
注意:bind会根据你的参数类型来决定调用call或apply,所以args可以是一个个数据,也可以是一个数组哦。
返回值:拷贝的对象
var obj = { name: ‘xxx‘, age: 50 }; var copyObj = angular.copy(obj); console.log(copyObj); //$ Object {name: "xxx", age: 50}
返回值:boolean
angular.equals(3, 3); //$ true angular.equals(NaN,NaN); //$ true angular.equals({name:‘xxx‘},{name:‘xxx‘}); //$ true angular.equals({name:‘xxx‘},{name:‘yyy‘}); //$ false
返回值:拓展的对象
var dst = {name: ‘xxx‘, country: ‘China‘}; var src = {name: ‘yyy‘, age: 10}; angular.extend(dst, src); console.log(src); //$ Object {name: "yyy", age: 10} console.log(dst); //$ Object {name: "yyy", country: "China", age: 10}
返回值:obj
var obj = {name: ‘xxx‘, country: ‘China‘}; angular.forEach(obj, function (value, key) { console.log(key + ‘:‘ + value); }); //$ name:xxx //$ country:China var array = [‘xxx‘, ‘yyy‘]; angular.forEach(array, function (item, index) { console.log(index + ‘:‘ + item + ‘ form ‘ + this.country); }, obj); //$ 0:xxx form China //$ 1:yyy form China
返回值:json对象
var json = angular.fromJson(‘{"name":"xxx","age":34}‘); console.log(json); //$ Object {name: "xxx", age: 34}
返回值:字符串
angular.toJson({name:‘xxx‘}); //$ "{"name":"xxx"}" angular.toJson({name:‘xxx‘},true); //$ "{ //$ "name": "xxx" //$ }" angular.toJson({name:‘xxx‘},10); //$ "{ //$ "name": "xxx" //$ }"
返回值:第一个参数
console.log(angular.identity(‘xxx‘,‘yyy‘)); //$ xxx
返回值:boolean
angular.isArray(3); //$ false angular.isArray([]); //$ true angular.isArray([1, 2, 3]); //$ true angular.isArray({name: ‘xxx‘}); //$ false
返回值:boolean
angular.isDate(‘2012-12-02‘); //$ false angular.isDate(new Date()); //$ true
返回值:boolean
angular.isDefined(undefined) //$ false angular.isDefined([]); //$ true
返回值:boolean
angular.isUndefined(undefined) //$ true angular.isUndefined([]); //$ false
返回值:boolean
angular.isFunction(function(){}); //$ true angular.isFunction(3); //$ false
返回值:boolean
angular.isNumber(4); //$ true angular.isNumber(‘xxx‘); //$ false angular.isNumber(new Number(4)); //$ false angular.isNumber(Number(4)); //$ true
返回值:boolean
angular.isObject(‘xxx‘); //$ false angular.isObject(null); //$ false angular.isObject([]); //$ true angular.isObject(function(){}); //$ false angular.isObject({name:‘xxx‘}); //$ true
返回值:boolean
angular.isString(4); //$ false angular.isString(‘xxx‘); //$ true angular.isString(new String(‘xxx‘)); //$ false angular.isString(String(‘xxx‘)); //$ true
返回值:改变后的新字符串
var newString = angular.lowercase(‘XXyyZZ‘); console.log(newString); //$ xxyyzz
返回值:改变后的新字符串
var newString = angular.uppercase(‘XXyyZZ‘); console.log(newString); //$ XXYYZZ
作用:空函数
var flag = false; flag ? console.log(‘xxx‘) : angular.noop();
标签:
原文地址:http://www.cnblogs.com/laneyfu/p/4718390.html