2

This is what I want to have:

function MyClass() {
   this.some = new Array();
   this.another = new Array();
}

MyClass.prototype.some_method = function(element) {
   // some work with this.some
}

MyClass.prototype.another_method = function() {
   this.another.map(function(el) {
     this.some_method(el);   // error code
   });
}

But I get error with it:

Uncaught TypeError: Object [object Window] has no method 'empty_cell' 

Is it possible to call MyClass methods in the anonymous function?

1 Answer 1

4

You can pass this scope as a second parameter to the map function, like this:

MyClass.prototype.another_method = function() {
   this.another.map(function(el) {
     this.some_method(el);
   }, this); // added this
}

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.