what is the difference between these two functions? | SoloLearn: Learn to code for FREE!

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

2/29/2020 5:38:52 AM

Balram Singh

1 Answer

New 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);