An Essay on JS (Ii.)

Source: Internet
Author: User

Closed Package
  1. Why use closures: for a variety of reasons, we may use properties within the function, but because the properties defined inside the function are local variables and cannot be used outside the function, we can use the closed package to get the properties we want.
  2. What are the benefits of doing this? Because we can not only promote the variables within the function in a disguised manner, but also avoid the problem of variable name collisions, variables can persist in memory.
  3. Having said so much, what about closures?
    function Test () {    var a = 0    returnfunction  test01 () {         a+ +          return  Console.log (a)    }}// call Testvar a =test () A ()  //1A ()//2A ()//3

JS's built-in object
    1. Arguments is defined only inside the function, and the arguments of the function are saved
    2. Array Object
    3. Date Day Object
    4. Math Mathematical Object
    5. String String Object
String

? CharAt (IDX): Returns the character at the specified position

? IndexOf (CHR): Returns the position of the specified substring, from left to right. No return-1 found

? SUBSTR (M,n): Returns the position of the given string starting at m, taking n characters, if the argument n is omitted, it means that the end of the string is taken.

? SUBSTRING (m,n): Returns the position of the given string from M, to the end of N, or to the end of the string if the argument n is omitted.

? toLowerCase (): Converts all characters in a string to lowercase.

? toUpperCase (): Converts all characters in a string to uppercase.

? Length: property, which is not a method, returns the lengths of a string.

JS Object

object is the core concept of JavaScript and the most important data type. All of JavaScript's data can be treated as objects. JavaScript provides multiple built-in objects, such as String, Date, Array, and so on.  Objects are special data types with properties and methods. Simply put, the so-called object, is an unordered set of data, by a number of "key-value pairs" (key-value) composition. With JavaScript, we can create our own objects. The JavaScript object satisfies this "key-value pair" format that we become in JSON format, and we meet very much later, that is, the great JSON object

    1. The creation of the object var a = {}; var a = {Name:zs,age:12} var a = new object () a.name= "Zs" a.age=12 var a = object.create (null); Here null can be placed in an object , the new a inheritance is put into all the properties of the object
    2. Serialization and deserialization of an object 1) json.stringify (object) serializes objects into string 2) Json.parse (JSONSTR) deserializes the Jsonstr and converts the string into a Like.
    3. Eval () Usage eval can execute strings directly such as ("Console.log (' Hello, console ') executes this sentence, you can print the string directly on the console), and you can deserialize the object
      var jsonstr = "{name: ' Zs ', age:12}
      First parsing method: eval ("var a =" + Jsonstr)
      The second method of parsing: var a = eval ("(" ("+jsonstr+")) is used here () to amplify the string jsonstr because of the self-cause of the Eval method, and if there is no parenthesis, the eval execution string here does not return an object. Because it would assume that the statement here is just a normal statement of {}, there is no object to return, and a value is undefined.
    4. The use of this is similar to this in Java, who calls the function this returns the object, and if the window is called, returns the Window object, which is the window that script executes the code block
      Object called this, which returns the object, which is the ancestor of the function.

An Essay on JS (Ii.)

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.