I am new to Javascript, but have Java experiance.
const person = {
name: "bin",
walk() {
console.log(this);
}
};
person.walk();
const per1 = person;
per1.name = "cin";
per1.walk();
const animal = {
type: "2",
m2() {
console.log("type");
}
};
const walk1 = person.walk.bind(animal);
walk1();
person.walk();
I am failing to understand the output at line number 1 which prints a value of cin
for name
. When the code executes at person.walk()
, the value of name has not changed. Why is the value being printed as cin?
{name: "bin", walk: ƒ}name: "cin"walk: ƒ walk()__proto__: Object
{name: "cin", walk: ƒ}name: "cin"walk: ƒ walk()__proto__: Object
{type: "2", m2: ƒ}type: "2"m2: ƒ m2()__proto__: Object
{name: "cin", walk: ƒ}name: "cin"walk: ƒ walk()__proto__: Object