Angularjs learning notes-tool method, angularjs learning notes

Source: Internet
Author: User
Tags tojson

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:

    • String: string
  • Return Value: json object

    var json = angular.fromJson('{"name":"xxx","age":34}');console.log(json); //$ Object {name: "xxx", age: 34}
Angular. toJson (json, pretty)
  • Purpose: convert a json object to a string.
  • Parameters:

    • Json: json
    • Pretty: boolean number controls the string output format
  • Return Value: String

    angular.toJson({name:'xxx'});//$ "{"name":"xxx"}"angular.toJson({name:'xxx'},true);//$ "{//$    "name": "xxx"//$ }"angular.toJson({name:'xxx'},10);//$ "{//$            "name": "xxx"//$ }"
Angular. identity (value)
  • Purpose: return the first parameter of the function.
  • Parameters:

    • Value: Parameter
  • Return Value: the first parameter.

    console.log(angular.identity('xxx','yyy')); //$ xxx
Angular. isArray (value)
  • Purpose: Determine whether a data is an array.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isArray(3); //$ falseangular.isArray([]); //$ trueangular.isArray([1, 2, 3]); //$ trueangular.isArray({name: 'xxx'}); //$ false
Angular. isDate (value)
  • Purpose: Determine whether a data is of the Date type.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isDate('2012-12-02'); //$ falseangular.isDate(new Date()); //$ true
Angular. isDefined (value)
  • Purpose: Determine whether a data is of the defined type.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isDefined(undefined) //$ falseangular.isDefined([]); //$ true
Angular. isUndefined (value)
  • Purpose: Determine whether a data is of the undefined type.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isUndefined(undefined) //$ trueangular.isUndefined([]); //$ false
Angular. isFunction (value)
  • Purpose: Determine whether a data is a function.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isFunction(function(){}); //$ trueangular.isFunction(3); //$ false
Angular. isNumber (value)
  • Purpose: Determine whether a data is of the Number type.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isNumber(4); //$ trueangular.isNumber('xxx'); //$ falseangular.isNumber(new Number(4)); //$ falseangular.isNumber(Number(4)); //$ true
Angular. isObject (value)
  • Purpose: Determine whether a data is an object.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isObject('xxx'); //$ false      angular.isObject(null); //$ falseangular.isObject([]); //$ trueangular.isObject(function(){}); //$ falseangular.isObject({name:'xxx'}); //$ true
Angular. isString (value)
  • Purpose: Determine whether a data string is used.
  • Parameters:

    • Value: Data
  • Return Value: boolean

    angular.isString(4); //$ falseangular.isString('xxx'); //$ trueangular.isString(new String('xxx')); //$ falseangular.isString(String('xxx')); //$ true
Angular. lowercase (string)
  • Purpose: decrease the number of uppercase letters in a string.
  • Parameters:

    • String: string
  • Returned value: the new string after the change

    var newString = angular.lowercase('XXyyZZ');console.log(newString); //$ xxyyzz
Angular. uppercase (string)
  • Function: converts lowercase letters of a string to uppercase letters.
  • Parameters:

    • String: string
  • Returned value: the new string after the change

    var newString = angular.uppercase('XXyyZZ');console.log(newString); //$ XXYYZZ
Angular. noop ()
  • Role: Empty Function

    var flag = false;    flag ? console.log('xxx') : angular.noop();

Reprinted from http://segmentfault.com/a/1190000002625738

Test address http://www.linchaoqun.com/html/angular/function.jsp

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.