+ 1
what is the difference between these two functions?
1; const chameleon = { eyes: 2, lookAround: function () { console.log(`I see you with my ${this.eyes} eyes!`); } }; 2: function whoThis () { this.trickyish = true } chameleon.lookAround(); whoThis();
1 Answer
+ 6
First example has an object literal with method lookAround.
Second example has a constructor definition.
You can instantiate objects using constructor.
let obj = new whoThis();
alert(typeof obj);