According to MDN , the 2nd argument .map(fn, thisArg) is what you want to set for the this ptr parameter when the callback function is called, and it will be set for the global object (e.g. window ) if you don't pass the second argument.
So you can make your example work like this:
function myClass() { this.nums = [1,2,3]; this.divisor = 2; } myClass.prototype.divideNumsByDivisor = function(){ return this.nums.map(function(num) { return num*this.divisor; }, this); }
source share