Home >Web Front-end >JS Tutorial >What does this[] refer to? Discussion_javascript skills
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?