Reading "JavaScript advanced Programming" Note Two-variables, scopes, memory, and reference types

Source: Internet
Author: User
Tags time zones

variables, scopes, and memory issues
    1. There are two types of execution environment-Global and local
    2. The scope chain is longer, there are two cases: the catch block of the Try-catch statement, the WITH statement.
    3. JavaScript does not have block-level scopes, which are variables in the if,for loop, and are not destroyed after the block has ended.
    4. It is a good idea to manually disconnect the native JavaScript object from the DOM element.
Object type
    1. There are two ways to create an object instance: The new operator is followed by the object constructor, new object (), and the object literal notation is denoted by {}.
    2. You can use the square bracket notation to access the properties of an object, and the property to be accessed is placed in square brackets in the form of a string.
    3. Square brackets access the properties of an object, which can be accessed by a variable

      var propertyname = "Name"; Alert (Person[propertyname]);

      The property name contains characters that cause syntax errors, or you can use square brackets

Array type
  1. There are two ways to create an instance of an object: The new operator is followed by the array constructor, the new object (), and the object literal representation is represented by [].
  2. The constructor of an array is not called when the array is created in the same way as the object, when it is called literal
  3. Detection array: Value instanceof array
  4. Array.isarray (value) supports ie9+ ...
  5. The ToString () method of the array returns a comma-delimited string of strings for each value string in the array; call valueof () returns or arrays
  6. Use push () and pop () to simulate the stack method, using push () and shift () to simulate the queue method
  7. The Concat () method creates a copy, adds the received parameter to the end of the copy, and does not change the original array
  8. Slice () receives a parameter that returns all items from the specified position to the end, and if two parameters, returns the item from the specified start position to the end position, excluding the end position. Also, the slice () method does not affect the original array.
  9. Splice () method
    Delete 2 parameters To delete the first item position, to delete the number of items, example splice (0,2)
    Insert One parameter Starting position, 0 (number of items to delete), the item to be inserted, example splice (2,0, "Red", "yellow")
    Replace One parameter Starting position, to delete the item number, the item to be inserted, example splice (2,1, "Red", "yellow")
  10. Iterative methods
    Every () Runs the given function for each item of an array, and returns TRUE if each item returns true
    Filter () Each item of an array runs the given function, and returns the list of items that the function returns True
    ForEach () Runs the given function for each item of an array, and the function does not return a value
    Map () Runs the given function for each item of the array, returning each time the result of the call is returned
    Some () Runs the given function for each item of an array, and returns True if the function returns true for either item

    Support for iterative methods requires ie9+

  11. Narrowing method Values.reduce (function (Prev,cur,index,array) {}), also requires IE + +
Date type
    1. UTC creation time: var allfives = new Date (DATE.UTC (2005,4,5,17,55,55,55)), originally according to the book, should be May 5, 2005 5:55 P.M. 55 seconds, But I run the time is May 6, 2005 1:55 55 seconds, because my time zone is East 8, plus 8 o'clock
    2. var allfives = new Date (2005,4,5,17,55,55,55), the time of creation can be the corresponding result.
    3. Date.now () supported browsers for ie9+
    4. In browsers that do not support the now () method, you can use the following methods to count the time between two pieces of code
                  var start = +new Date ();                dosomething ... var end = +new Date ();                 Console.log (End-start);            
    5. Method of date formatting
      toDateString () Display weekday, month, day, and year in a realistic-specific time format
      toTimeString () Display hours, minutes, seconds, time zones in a realistic-specific time format
      toLocaleDateString () Display days, months, days, and years in a locale-specific time format
      toLocaleTimeString () Display hours, minutes, seconds in a realistic-specific time format
      toUTCString () Full UTC date in a realistic-specific format
Regular expressions
  1. Regular expression: var expression =/pattern/flags;
  2. There are three flags: G is global, I table is case insensitive, M is multi-line matching
  3. RegExp Instance Properties
    Global Boolean value, whether the G flag is set
    IgnoreCase Boolean, whether the I flag is set
    LastIndex An integer that represents the character position at which to start searching for the next occurrence, starting from 0
    Multiline Boolean value, whether the M flag is set
    Source A string representation of a regular expression that is returned in literal form rather than in the character pattern in the passed-in constructor
  4. Regular Expression Constructor properties
    Long attribute name Short attribute name Description
    Input $_ The last string to match, opera is not implemented
    Lastmatch $& Last match, opera not implemented
    Lastparen $+ Last matched capture group, opera not implemented
    Leftcontext $` Text before lastmatch in the input string
    Multiline $* Boolean value indicating whether to use multiline mode, IE and opera are not implemented
    Rightcontext $ Text after lastmatch in the input string
  5. The method of the regular expression var matches = Pattern.exec (text) "Returns the result set" and pattern.test (text) "Returns True, false".
  6. The Text.match (pattern) method of string type is the same as pattern.exec (text)
function type
    1. Arguments.callee () calls the current function, which is not supported by strict mode
    2. This refers to the function object on which the function is executed
    3. Caller This function holds a reference to a call to the current function and returns null if the current function is called in a global variable
    4. Each function contains two properties: Length and prototype, where length indicates the number of named arguments that you want to receive
String type
    1. The second parameter of the replace () method can be a function that passes three parameters in the case of only one match: pattern match, pattern match position in string, and original string
                  function Htmlescape (text) {                    return Text.replace (/[<> "&]/g,function (match,pos,originaltext) {                        Switch (match) {case                            "<":                                return "<";                            Case ">":                                return ">";                            Case "&":                                return "&";                            Case "\" ":                                Return" "";}}                    );                            
    2. There are several methods related to the matching pattern: match (), search (), replace (), and split () can pass in the regular expression.
Math Object
    1. Approximate values are calculated as follows: Ceil (), round (), Floor ()
    2. A method of randomly selecting a value from an integer range: value = Math.floor (Math.random () * Total number of possible values + first possible value)

Reading "JavaScript advanced Programming" Note Two-variables, scopes, memory, and reference types

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.