Angularjs learning notes-tool method, angularjs learning notes
Angular. bind (self, fn, args)
- Purpose: return a new function. Bind this function to self.
- Parameters:
- Self: context object of the new function
- Fn: function to be bound
- Args: parameters passed to the Function
Returned value: this points to the new function of 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 AmericanbindFn(); //$ yyy is form China
Note: bind determines whether to call or apply based on your parameter type. Therefore, args can be data or an array.
Angular. copy (source, [destination])
- Role: Object deep copy
- Parameters:
- Source: source object
- Destination: the object to be copied.
Returned value: Copied object
var obj = { name: 'xxx', age: 50};var copyObj = angular.copy(obj);console.log(copyObj); //$ Object {name: "xxx", age: 50}
Angular. equals (o1, o2)
- Role: normal comparison and deep comparison of Objects
- Parameters:
- O1: comparison object
- O2: comparison object
Return Value: boolean
angular.equals(3, 3); //$ trueangular.equals(NaN,NaN); //$ trueangular.equals({name:'xxx'},{name:'xxx'}); //$ trueangular.equals({name:'xxx'},{name:'yyy'}); //$ false
Angular. extend (dst, src)
- Purpose: expand an object
- Parameters:
- Dst: Extended object
- Src: source object
Return Value: Extended object
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}
Angular. forEach (obj, iterator, [context])
- Purpose: traverse objects
- Parameters:
- Obj: Object
- Iterator: iterative function
- Context: context in iterative Functions
Return Value: obj
var obj = {name: 'xxx', country: 'China'};angular.forEach(obj, function (value, key) { console.log(key + ':' + value);});//$ name:xxx//$ country:Chinavar 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
Angular. fromJson (string)
- Purpose: convert a string to a json object.
- Parameters:
Return Value: json object
var json = angular.fromJson('{"name":"xxx","age":34}');console.log(json); //$ Object {name: "xxx", age: 34}
Angular. toJson (json, pretty)
Angular. identity (value)
Angular. isArray (value)
Angular. isDate (value)
Angular. isDefined (value)
Angular. isUndefined (value)
Angular. isFunction (value)
Angular. isNumber (value)
Angular. isObject (value)
Angular. isString (value)
Angular. lowercase (string)
Angular. uppercase (string)
Angular. noop ()
Reprinted from http://segmentfault.com/a/1190000002625738
Test address http://www.linchaoqun.com/html/angular/function.jsp