2017.05.06FreeCodeCamp programming JS Object-oriented Programming learning

Source: Internet
Author: User

1. How to construct the object:

② uses constructors to create objects. Constructors usually start with uppercase letters to differentiate themselves from other normal functions.

In the constructor, this point to the object that was created by this constructor.

2. How to use constructors: When using a constructor, we call it by using a keyword before it new

To use the new keyword to invoke the constructor. Because only then does JavaScript know that it is going to construct a new object and point the constructor to the this new object.

Now, when myCar Car created, he can be used like a normal object, including creating, accessing, modifying its properties , and so on, just as we do with other objects.

3. Focus on understanding and mastering the points of knowledge here: We have written 构造函数 well before, but we do not want to always create the same object, how to do?

In order to solve this problem, we want to 构造函数 add to the 参数 .

4. Private properties and private methods of objects: objects have their own characteristics, called 属性 , objects have their own functions, called 方法

can be created 私有属性 and 私有方法 , both of them are inaccessible outside the object

We are in 构造函数 , using our familiar var keywords to create variables to replace the creation we use this 属性 .

5. Iterative algebraic groups: map methods can be easily iterated by algebraic groups

mapThe method iterates through each element of an algebraic group and processes each element according to the callback function, and finally returns a new array.

Note that this method does not change the original array.

In our case, the callback function has only one parameter, the value (parameter) of the element in the array val ,

But in fact, your callback function can also support multiple parameters, such as: The index of the element index , the original array arr .

6. The array method reduce is used to iterate over an array and accumulate it into a value

reducewhen using a method, you pass in a callback function with the parameter of the callback function being an accumulator

reduceThe method has an optional second parameter, which can be used to set the initial value of the accumulator.

If the initial value is not defined here, the initial value becomes the first item in the array, and the currentVal second item in the array begins.

Use reduce the method to array add all the values in, and assign the result to the value singleVal .

7. Array conditional filtering: The filter method is used to iterate over an array and filter out the conforming elements according to the given conditions.

filtermethod to pass in a callback function that carries a parameter that is an item of the current iteration

The items returned by the callback function are true persisted in the array, and false the returned items are filtered by a group

8. Array sorting: using sort methods, you can easily sort the elements in an array in alphabetical order or numerically.

Unlike the array method that we used earlier, the sort method will change the original array and return the sorted array instead of just returning a new array.

sortYou can pass the comparison function as a parameter . The comparison function has a return value, when it is a less than b , returns a negative number, a and returns a positive if it is greater than b 0 when equal.

If the comparison function is not passed in, it will turn the values all into strings and order alphabetically.

9. Flip an array: You can use reverse methods to flip an array. This function is not required, the callback function is used directly.

NewArray = Array.reverse ();

10. Merging arrays: concat methods can be used to merge the contents of two arrays into an array

concatThe parameter of the method should be an array. The array in the parameter is stitched to the back of the original array and returned as a new array.

11. String Segmentation Array: use split the method to split the string into arrays by the specified delimiter.

To split pass a parameter to the method, this parameter will be used as a delimiter.

return: ["Split", "Me", "into", "an", "array"]

12. The array is converted to a string: Use the join method to convert the array to a string, where each element can be concatenated with the connector you specify, which is the parameter you want to pass in.

Return:

2017.05.06FreeCodeCamp programming JS Object-oriented Programming learning

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.