Skip to content

Instantly share code, notes, and snippets.

@ramazankanbur
Created November 11, 2019 13:05
Show Gist options
  • Save ramazankanbur/5d7a20547eb0142a3da349067d3e8b63 to your computer and use it in GitHub Desktop.
Save ramazankanbur/5d7a20547eb0142a3da349067d3e8b63 to your computer and use it in GitHub Desktop.
//ES5 that, this ataması yapılmalı ya da bind edilmeli
var obj = {
nums: [1, 2, 3, 4, 5, 6, 10],
fives: [],
hop: function() {
var that = this;
this.nums.forEach(function(v) {
if(v % 5 ===0)
that.fives.push(v);
});
console.log(this.fives);
}
};
obj.hop();
console.log('----------------------');
//ES6
var obj1 = {
nums: [1, 2, 3, 4, 5, 6, 10],
fives: [],
hop:function () {
this.nums.forEach((v) => {
if(v % 5 ===0)
this.fives.push(v);
});
console.log(this.fives);
}
};
obj1.hop();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment