Home > Web Front-end > JS Tutorial > What does this[] refer to? Discussion_javascript skills

What does this[] refer to? Discussion_javascript skills

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-05-16 19:16:13
Original
1229 people have browsed it

Code
theMonths = new MakeArray(12)
// load array with English month names
function MakeArray(n) {
this[0] = "anuary"
this[1] = "February"
this[2] = "March"
this[3] = "April"
this[4] = "May"
this[5] = "June"
this[6] = "July"
this[7] = "August"
this[8] = "September"
this[9] = "October"
this[10] = " November"
this[11] = "December"
this.length = n
return this
}
This is a piece of code from the Java Script Bible 4th Edition.
This kind What does the usage of this mean? What is the role of JavaScript's this and anonymous obj?
This kind of usage can only be limited to inside the function
Throwing exception love wrote
This way, you can use it in other places
Code
var my = new Object ();
my.MakeArray= MakeArray;
my.MakeArray(10);
I did see a similar usage
Code
// create basic array
theMonths = new MakeArray(12)
If the usage of this[] means that this is an array object
Then
Code
this.length = n
This seems to make this another array object and an int variable
This then looks like an object of an anonymous class
Can it be understood this way?

Related labels:
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
Latest Issues
Why is this ID written like this?
From 1970-01-01 08:00:00
0
0
0
Small question about $this
From 1970-01-01 08:00:00
0
0
0
javascript - es6中this
From 1970-01-01 08:00:00
0
0
0
This file demo.mp4
From 1970-01-01 08:00:00
0
0
0
What's the use of this?
From 1970-01-01 08:00:00
0
0
0
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template