Javascript really has no classes. What he has is prototypes - an instance of an object that is used as a template for new objects.
The way you created your object is to use a constructor literal. It is concise, but suffers from the fact that it cannot be added or use complex instructions in its design.
Another way:
function SomeClass(value) { if (value < 0) { this.field = -1; } else { this.field = value; } }
And a new instance is created as follows:
var obj = new SomeClass(15);
This allows you to use conditional logic, loops, and other more complex programming methods when building your object. However, we can only add instance fields, not "class" fields. You add class fields by changing the prototype functions of your creator object.
MyClass.prototype.fieldSquared = function () { return this.field * this.field; }
This is a more complete overview of creating objects and prototypes in Javascript.
Dunes source share