Answer the question
In order to leave comments, you need to log in
Why can't call the method?
I ran into a problem that I can't solve.
There is a constructor:
function Constructor(a, b, c){
this.a = a;
this.b = b;
...
}
Constructor.prototype.method = function(){
...
}
function init(){
var arr = [];
for ... {
arr.push(new Constructor(a, b, c));
}
arr.forEach(function(item){
item.method(); // в этом месте ошибка TypeError: item.method is not a function
}
}
Answer the question
In order to leave comments, you need to log in
'use strict'
function Constructor(a, b, c){
this.a = a;
};
Constructor.prototype.method = function(){
console.log(`Run method: this.a: ${this.a}`);
};
function init(n){
var arr = [];
for(let i = 0; i < n; i++){
arr.push(new Constructor(i));
}
arr.forEach(function(item){
item.method();
});
};
init(10);
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question