Angularjs Learning Notes-tool methods

Source: Internet
Author: User
Tags string to json tojson

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 form ' +country); }};varSelf ={name:' YYY '};varBINDFN = 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 depends on your parameter type to invoke call or apply, so args can be a data or an array.

Angular.copy (source, [destination])
    • function: Deep copy of Object
    • Parameters:
      • Source: Origin Object
      • Destination: Copied objects
    • Return value: The copied object

      var obj = {    ' xxx ',    +}; var copyobj =//$ Object {name: "xxx", age:50}

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

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//$ Object {name: "yyy", age:10}//
           
            $ Object {name: "yyy", Country: "China", age:10}
           

Angular.foreach (obj, iterator, [context])
  • Role: Traversal of objects
  • Parameters:
    • Obj: Object
    • Iterator: Iterative functions
    • Context: Contexts in an iterative function
  • return value: obj

    varobj = {name: ' xxx ', Country: ' China '};angular.foreach (obj,function(value, key) {Console.log (key+ ': ' +value);});//$ name:xxx//$ Country:chinavarArray = [' 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)
    • Function: String to JSON object
    • Parameters:
      • String: Strings
    • Return value: JSON object

      var json = Angular.fromjson (' {' name ': ' xxx ', ' age ': ' + '//$ Object {name: ' xxx ', age:34} 

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  Span style= "color: #000000;" >); // $ "{ $ " Name ":" XXX " // $}"  angular.tojson ({name:  ' xxx '},10 //            $ "{ $ "Name": "XXX"  // $} " 

     

Angular.identity (value)
    • Function: Returns the first argument of this function
    • Parameters:
      • Value: Parameter
    • Return value: First parameter

      // $ xxx

Angular.isarray (value)
    • Function: Determine whether a data is an array
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ false // $ true // $ true // $ false

Angular.isdate (value)
    • Function: Determine whether a data is a date type
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ falseangular.isdate (new//$ true

angular.isdefined (value)
    • Function: Determine whether a data is a defined type
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ false // $ true

angular.isundefined (value)
    • Function: Determine whether a data is a undefined type
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ true // $ false

Angular.isfunction (value)
    • Function: Determine whether a data is a function
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      Angular.isfunction (function//$ true//$ false

Angular.isnumber (value)
    • Function: Determine whether a data is a number type
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ true // $ falseAngular.isnumber (new//$ false//$ true

Angular.isobject (value)
    • Function: Determine whether a data is an object
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ false       Angular.isobject (null//$ false//$ trueangular.isobject ( function // $ false // $ true

Angular.isstring (value)
    • Function: Determine whether a data is a string
    • Parameters:
      • Value: Data
    • Return Value: Boolean

      // $ false // $ trueangular.isstring (new//$ false//$ true

Angular.lowercase (String)
    • Function: Lowercase the string uppercase
    • Parameters:
      • String: Strings
    • Return value: The new string after the change

      var newstring = angular.lowercase (' xxyyzz '//$ xxyyzz

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 '//$ xxyyzz

Angular.noop ()
    • Function: null function

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

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.