+ 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();

29th Feb 2020, 5:38 AM
Balram Singh
Balram Singh - avatar
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);
29th Feb 2020, 5:43 AM
šŸ‡®šŸ‡³OmkaršŸ•‰
šŸ‡®šŸ‡³OmkaršŸ•‰ - avatar