You are on page 1of 1

const obj = {

name:"tony",
city:"New-York",
showName(){
console.log(this.name + " " + this.city) //this is accessbile here
}
}

const video = {
title: 't',
tags: ['a','b','c'],
showTags(){
this.tags.forEach(function(tag){ //this is the regular callback function not a
method of the object
console.log(this.title,tag) //referencing to the window object
},this) //inside the forEach function we can pass the this and it will referece
to the current video object
// here we are still in the execution context of the showTags method so this
will refer to the video object
}
}

You might also like