Skip to content

Instantly share code, notes, and snippets.

@nmtitov
Created November 15, 2012 22:52
Show Gist options
  • Select an option

  • Save nmtitov/4082080 to your computer and use it in GitHub Desktop.

Select an option

Save nmtitov/4082080 to your computer and use it in GitHub Desktop.
var x = 20;
var A = function () {
this.list = [1, 2, 3, 4, 5];
this.x = 10;
}
A.prototype.test = function() {
this.list.forEach(function (element) {
console.log(Math.pow(element, this.x));
});
}
var a = new A();
a.test();
var x = 20;
var A = function () {
this.list = [1, 2, 3, 4, 5];
this.x = 2;
}
A.prototype.test = function() {
var self = this; // или var that = this;e
this.list.forEach(function (element) {
console.log(Math.pow(element, self.x));
});
}
var a = new A();
a.test();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment