Home > Web Front-end > JS Tutorial > Introduction to the meaning of that in javascript_Basic knowledge

Introduction to the meaning of that in javascript_Basic knowledge

WBOY
Release: 2016-05-16 16:48:22
Original
1278 people have browsed it

You may find this sentence in the code written by others: var that = this;, what does this mean?

In JavaScript, this represents the current object.

var that=this copies the current this object into the that variable. What's the point of doing this?

Copy code The code is as follows:

$('#zhetenga').click (function(){
//This is the one that was clicked #zhetenga
var that = this;
$('.zhetenga').each(function(){
//This is. The current object in the zhetenga loop
//that is still the one that was clicked just now #zhetenga
});
});

As you can see, this object is in the program It will change at any time, and after var that=this, that still points to this at that time before it changes, so that the original object will not be found.
Related labels:
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