Home > Web Front-end > JS Tutorial > body text

Detailed introduction about this object

零下一度
Release: 2017-06-15 15:15:15
Original
1457 people have browsed it

The this object of a function in JavaScript is the scope in which the function is executed (for example: when a function is called in the global scope of a web page, the this object refers to window). This in JavaScript is very different from this in object-oriented languages ​​such as Java. The bind(), call() and apply() functions further extend the flexibility of this. To ensure readability, this article uses free translation rather than literal translation. In addition, the copyright of this article belongs to the original author, and the translation is for learning only. If you don't understand the JavaScript keyword "this" deeply enough, you may sometimes fall into unexpected pits. Here we have summarized 5 general rules to help you determine what this actually points to. Although not all situations are covered, most everyday situations can be correctly inferred using these rules. The value of this is usually determined by the execution environment of the function, which means it depends on how the function is called; every time the same function is called, this may point to a different object; the global object (Global Object) opens the Chrome browser Developer Panel (W

1. Detailed explanation of this based on JavaScript

Detailed introduction about this object

##Introduction: The this object of a function in JavaScript is the scope in which the function is executed (for example: when a function is called in the global scope of a web page, the this object refers to the window) .

2. Detailed explanation of the definition of php variables and code examples of scope

Detailed introduction about this object

Introduction: 1. Definition and scope variables of PHP variables: When calling attributes in a method, echo cannot be used directly. $this object 1 must be used in the class. Definition and use of PHP variables: letters underlined Starting with ^[a-zA-Z_]\w* 2. Scope of PHP variables: Local scope: Variables defined inside a function can only work inside the function Global scope

3. 4 Methods to Create Objects in JavaScript Detailed Graphical Code Explanation

Detailed introduction about this object

Introduction: 1. Disadvantages of the factory pattern: it does not solve the problem of object identification, that is, how to know the type of an object. 2. Constructor pattern Compared with the factory pattern: 1. No objects are explicitly created. 2. Properties and methods are assigned directly. this object 3. There is no return statement. To create an instance of person, you must use the new operator. Calling the constructor in this way actually goes through 4 steps: 1. Create a new object 2. Assign the scope of the constructor to New object 3. Execute the code in the constructor 4. Return the new object. Creating a custom constructor can mark its instance..

4. JavaScript Closure- Variables and this objects in closures

Detailed introduction about this object

##Introduction: The mechanism of scope chain in JavaScript will cause Some side effects: Closures can only get the last value of any variable in the function. When using closures, we must pay attention to the variable value, because this is where things often go wrong.

##5. Detailed explanation of how to write and function closures in JavaScript

##Introduction : This article introduces you to closures in JavaScript, including an understanding of the concept of closures in JS, several ways to write and use closures, the main functions of closures, closures and this objects, closures and memory leaks, and the use of closures The relevant knowledge of attention points is very good and has reference value. Friends who are interested can learn togetherDetailed introduction about this object

6.

Detailed explanation of the writing and function of closures in JavaScript

Detailed introduction about this object

Introduction: This article will introduce you to closures in JavaScript, including an understanding of the concept of js closures, several ways to write and use closures , the main functions of closures, closures and this objects, closures and memory leaks, and relevant knowledge about the points to note when using closures. It is very good and has reference value. Friends who are interested should learn together

7. riot.js learning [2] mixin

Detailed introduction about this object

##Introduction: In riot.js, there is a very important concept, which is mixin. As the name suggests, its approximate function is "mixing". Mix the properties and methods of the object into the current context. The common understanding is that it is the this object.

8. How to use bind() and bindTo() of PHP Closure class?

Introduction: Read the PHP manual about the usage of Closure's bind and bindTo. I really don't understand it and don't understand the concept. For example, Closure::bind, the manual says "copies a closure and binds the specified $this object and class scope". How to understand this? In what form are closures and $this bound together...

9. PHP7's Closure::call javascript closure need for closure google closure

Introduction: closure,php7:PHP7's Closure::call:Closure class: Anonymous function (introduced in PHP 5.3) will generate objects of this type. This class can be bound to a class or object, that is, custom methods are dynamically added to the class or object. The method used before php7 is Closure::bind: copy a closure and bind the specified $this object and class scope. . This method is the static version of Closure::bindTo() Closure::bindTo: copies the current closure object and binds the specified $this object and class scope. Create

10. An example explanation of the difference between apply, call and bind in javascript

Introduction: In JS, Apply, call and bind are all used to change the point of the this object of the function, so what are the differences between them. This article introduces the differences between apply, call and bind to coders. Coders in need can refer to it.

[Related Q&A recommendations]:

javascript - bind().call() usage issues in ECMAScript

Isn’t JavaScript’s this object an internal object of the function?

javascript - es6 inheritance, super method

javascript - this object in JS

Regarding this object in javascript, why does the global variable be referenced in the closure function?

The above is the detailed content of Detailed introduction about this object. For more information, please follow other related articles on the PHP Chinese website!

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template