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();
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();