what is the difference between these two functions? | Sololearn: Learn to code for FREE!
New course! Every coder should learn Generative AI!
Try a free lesson
+ 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