const obj = {
name: 'obj',
method1: function(){
console.log(this) // this = obj
},
objInObj: {
name: 'oio',
oioMethod(){ // ES6 Syntactic sugar: makes code short and easy to write! Allows defining functions this short way!
console.log(this) // this = objInObj
}
},
arr: [0, 1, 2],
newArr: [],
method2 () {
/*
this.arr.forEach(
// This is NOT a method! It's just an anonymous function I created
// -> cannot use this
function(number){
this.newArr.push(number*100)
}.bind(this) // Can use it by binding!
// -> But are you going to write this long...?
// => The arrow function was created because of this!
)//obj
*/
(number) => {
this.newArr.push(number * 100)
}
}
}