Search posts, tags, users, and pages
In this article, I will talk about how you can determine where this keyword points to.
Lim Woojae
@jaylog · Sydney
Computer Science @UNSW
Markdown supported · ⌘↵ to post
shubham
i think you code look wrong in this part
const obj = { name: "John Doe", myFunc() { printNmae: () => { console.log(this.name); } }, }; obj.printName() // ''
you can't access the printNmae , for accessing the printNmae you have to return it. just do
const obj={ name:"John Doe", myFunc(){ return { printNmae:()=>{console.log(this.name)} } } } obj.myFunc().printNmae();
Got it :) thank you for pointing it out!
shubham
i think you code look wrong in this part
const obj = { name: "John Doe", myFunc() { printNmae: () => { console.log(this.name); } }, }; obj.printName() // ''
you can't access the printNmae , for accessing the printNmae you have to return it. just do
const obj={ name:"John Doe", myFunc(){ return { printNmae:()=>{console.log(this.name)} } } } obj.myFunc().printNmae();