0
roughly, there are two ways to make an object in javascript... in your code, you use the 'literal' way ( obj = { /* properties, methods */ } ), so you made one Object instance. the alternate way is to use a constructor function. equivalent of literal declaration would be: obj = new Object(); obj.property = ...; or with a custom contructor: function CustomObj(arg1,arg2,...) { // initialization of 'this' object with properties and methods } CustomObj.prototype.methodOrProperty = ...; methods (or properties) defined on prototype will be shared across different CustomObj instances (properties of prototype can be accessed through instance, but write will occurs on instance: often prototype hold only methods, and instance hold only properties). Then you can create an instance with: myObj = new CustomObj(42,"forty-two",...); Obviously, there are a lot of workaround to make a new instance (class syntaxic sugar, Object.create static method...)
2nd Feb 2021, 6:45 PM
visph
visph - avatar