function Dog(name, age) {
this.name = name;
this.age = age;
this.bark = function() {
this.name += " hello";
console.log(this.name);
(function() {
this.name += "a";
console.log(this.name);
})();
}
};
let dog = new Dog("tep", 2);
dog.bark();
can anyone please tell me what happened here? when I open the console, It print 2 lines which are
- tep hello
- a
every time I reload the page, it continue add the 'a' in line 2, and I saw in the window object, there is property "name"
- tep hello
- aa