Angularjs Learning Notes-tool methods

Source: Internet
Author: User
Tags string to json tojson

1.angular.bind (self, FN, args)
      • Function: Returns a new function that binds this function to the self

      • Parameters:
        Self: The context object for the new function

        fn: Functions that need to be bound

        Args: Arguments passed to a function

      • Return value: This new function that points to self

varobj ={name:' xxx ', Print:function(country) {Console.log ( This. Name + ' is from ' +country); }};varSelf ={name:' YYY '};varBINDFN = Angular.bind (self, obj.print, ' China ');//var bindfn = Angular.bind (self, obj.print, [' China ']);Obj.print (' American ');//xxx is from AmericanBINDFN ();//yyy is from China

> Note: Bind will decide to invoke call or apply depending on your parameter type, so args can be either data or an array.

2.angular.copy (source, [destination])
      • function: Deep copy of Object

      • Parameters:
        Source: Origin Object

        Destination: Copied objects

      • Return value: The copied object

var obj = {  ' Zuobaiquan ',  +}; var copyobj =//Object {name: "Zuobaiquan", age:20}
3.angular.equals (O1, O2)
      • Function: Normal comparison and deep comparison of objects

      • Parameters:
        O1: Objects to compare

        O2: Objects to compare

      • Return Value: Boolean

// true // true // true // false
4.angular.extend (DST, SRC)
      • Role: Expansion of objects

      • Parameters:
        DST: An 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}//note here the name becomes "yyy" at this time

  

5.angular.foreach (obj, iterator, [context])
      • Role: Traversal of objects

      • Parameters:
        Obj: Object

        Iterator: Iterative functions

        Context: Contexts in an iterative function

      • 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 + ' from ' + this.country;}, obj.//0:xxx from china//1:yyy

  

6.angular.fromjson (String)
      • Function: String to JSON object
      • Parameters:
        String: Strings
      • Return value: JSON object
var json = Angular.fromjson (' {' name ': ' xxx ', ' age ': ') '; Console.log (JSON); Object {name: "xxx", age:34}

  

7.angular.tojson (Json,pretty)
      • Function: JSON object to String

      • Parameters:
        Json:json

        Pretty:boolean number control 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 "//}"

  

8.angular.identity (value)
      • Function: Returns the first argument of this function
      • Parameters:
        Value: Parameter
      • Return value: First parameter
Console.log (angular.identity (' xxx ', ' yyy ')); Xxx

  

9.angular.isarray (value)
      • Function: 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

  

10.angular.isdate (value)
      • Function: Determine whether a data is a date type

      • Parameters:
        Value: Data

      • Return Value: Boolean

Angular.isdate (' 2012-12-02 '); Falseangular.isdate (New Date ()); True

  

11.angular.isdefined (value)
      • Function: Determine whether a data is a defined type

      • Parameters:
        Value: Data

      • Return Value: Boolean

angular.isdefined (undefined)//falseangular.isdefined ([]); True

  

12.angular.isundefined (value)
      • Function: Determine whether a data is a undefined type

      • Parameters:
        Value: Data

      • Return Value: Boolean

angular.isundefined (undefined)//trueangular.isundefined ([]); False

  

13.angular.isfunction (value)
      • Function: Determine whether a data is a function
      • Parameters:
        Value: Data
      • Return Value: Boolean
Angular.isfunction (function () {}); Trueangular.isfunction (3); False

  

14.angular.isnumber (value)
      • Function: Determine whether a data is a number type
      • Parameters:
        Value: Data
      • Return Value: Boolean
Angular.isnumber (4); Trueangular.isnumber (' xxx '); Falseangular.isnumber (new number (4)); Falseangular.isnumber (number (4)); True

  

15.angular.isobject (value)
      • Function: 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
16.angular.isstring (value)
      • Function: Determine whether a data is a string

      • Parameters:
        Value: Data

      • Return Value: Boolean

Angular.isstring (4); falseangular.isstring (' xxx '); Trueangular.isstring (new String (' xxx ')); Falseangular.isstring (String (' xxx ')); True

  

17.angular.lowercase (String)
      • Function: Lowercase the string uppercase

      • Parameters:
        String: Strings

      • Return value: The new string after the change

var newstring = angular.lowercase (' Xxyyzz '); Console.log (newstring); Xxyyzz

  

18.angular.uppercase (String)
      • function: capitalizes the lowercase letter of a string

      • Parameters:
        String: Strings

      • Return value: The new string after the change

var newstring = angular.uppercase (' Xxyyzz '); Console.log (newstring); Xxyyzz

  

19.angular.noop ()

Function: null function

var flag = false;    Flag? Console.log (' xxx '): Angular.noop ();

  

If you think the article is good, please Bo Master drink a cup of tea Oh!!!

  

Angularjs Learning Notes-tool methods

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.