+ 1
Object Literal vs Constructor Function in JS
Hi! Guys Can anyone describe me the difference between Object Literal and Constructor Function in Javascript? I am confused at this topic...
3 ответов
+ 3
Object literals basically lets you create only a single object per initialisation and all the members have public scope. On the other hand constructor function lets you create multiple instances with members that could have private scope.
One would go for object literals if they kind of have some static data to hold and nothing much needs to change but you should use constructor function which helps in creating instances with different behaviour.
+ 1
object literal: simply an object
constructor function: it is the method which when called creates an object
0
Avinesh It makes sense. Thanks