why change() in constructor is not defined,it should be acessed through proto link in p.proto? why change() in constructor is not defined,it should be acessed through proto link in p.proto? why change() in constructor is not defined,it should be acessed through proto link in p.proto? why change() in constructor is not defined,it should be acessed through proto link in p.proto?
//the first change() is not defined ,why
class Person {
constructor() {
console.log(this)
console.log(this.__proto__)
// change()//output:is not define
}
change() {
console.log(this)
}
}
var p = new Person()
Object.prototype.change = function() {
console.log(' change in prototype')
}
change() //output:change in prototype
Try calling it with this keyword.
//the first change() is not defined ,why
class Person
{
constructor()
{
console.log(this)
console.log(this.__proto__)
this.change()//output:is not define
}
change()
{
console.log(this)
}
}
var p =new Person()
Object.prototype.change=function()
{
console.log(' change in prototype')
}
change()//output:change in prototype