Im looking for how to reach the variables inside a constructor without using 'this' keyword. If I put this in front of the variables, everything works fine.
function MyQueue() {
this.collection = [];
this.index = 0;
}
MyQueue.prototype.isEmpty = function () {
return this.collection.length === 0;
}
However, if I remove this keyword, I can't reach collection and index when I create an object. Is there any way to reach these variables?
function MyQueue ()
{
let collection = [];
let index = 0;
}
MyQueue.prototype.isEmpty = function()
{
return this.collection.length === 0;
}
This one doesn't work. How can I reach the collection and index inside a constructor? Thanks in advance.