New understanding of this pointer in JavaScript _ javascript skills

Source: Internet
Author: User
This article mainly introduces the new understanding of this pointer in JavaScript. this article describes the method call mode, function call mode, constructor call mode, and the understanding of this pointer in the Apply call mode, if you need this, you can refer to the previous understanding of this. This time, I made a deep understanding through JavaScript The Good Parts. (All debugging tasks can be viewed on the console, with the F12 key in the browser)

Let's take a look at this.

When we declare a function, each function has two additional parameters besides the parameters parameter in definition. one is this and the other is arguments ). Arguments is the parameter actually accepted by the function and is an array of classes. Arguments I will only give a brief introduction, focusing on the this pointer.

This is very important in object orientation. its value depends on the call mode. In JavaScript, there are 4 call modes: method call mode, function call mode, constructor call mode, and apply call mode.

Method call mode

When a function is an object attribute, we usually call this function a method of this object. When this method is called, this points to the object to which the method belongs.

The code is as follows:


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.