Prototype chain, constructor, arrow function, se6 array de-weight

Source: Internet
Author: User
Tags dedupe

Prototype chain

Examples are as follows:

var arr = [1, 2, 3];

Its prototype chain is:arr ----> Array.prototype ----> Object.prototype ----> null

In the same vein, we create a function:

function foo () {    return 0;}

Its prototype chain is:foo ----> Function.prototype ----> Object.prototype ----> null

Because Function.prototype apply() such methods are defined, all functions can invoke apply() methods.

It is easy to think that if the prototype chain is long, then accessing an object's properties will become slower because it takes more time to find it, so be careful not to make the prototype chain too long.

constructor function

constructor if not written new , this is a normal function that returns undefined . However, if new it is written, it becomes a constructor that binds to the this newly created object and returns by defaultthis。

That is, there is no need to write at the end return this; .

new Student()the created object also obtains a property from the prototype constructor , which points to the function Student itself.

Arrow functions

x = x * x

The above arrow functions are equivalent to:

function (x) {    return x * x;}

Se6 Array de-weight

function Dedupe (array) {            return array.from (new  Set (array));        }        Console.log (Dedupe ([//[+]

Array.form creating an array from a string

Prototype chain, constructor, arrow function, se6 array de-weight

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.