0
unexpected behaviour of 'this' keyword
var name="globalName" var age=12 var person={name:"abc", age:6, callMe: function () { return (`Name is:${this.name} Age is:${this.age}`) } } console.log(person.callMe()) // expected & actual output =>Name is:abc Age is:6 //calling a function var p1=person.callMe() console.log(p1) // expected & actual output =>Name is:abc Age is:6 //assign refrence of function var p2=person.callMe console.log(p2()) // Name is:undefined Age is:undefined
1 Réponse