I am doing my first javascript project that uses objects heavily. Due to how this works, almost all user objects are executed as follows:
namespaceobj = {};
namespaceobj.subobject = {};
namespaceobj.subobject.somefunction = function(arg, uments) {
}
namespaceobj.subobject.somedata = 10;
namespaceobj.othersubject = {};
namespaceobj.othersubject.somefunction = function(some, args) {
}
This is normal, since all user objects have only one instance (examples of sub-objects are the user interface, tools, general data, etc.).
However, I saw that the code did something like this (the syntax is probably incorrect, it's just from memory, seeing similar code)
function SomeClass() {
this.somedata = 42;
this.somefunction = function(a, few, args) {
}
}
someInstance = new SomeClass();
someInstance.somefunction();
Can someone explain how the “classes” in the second example work, and any errors that I may encounter when using them.
Macha source
share