I use jQuery if it is a difference.
No no. See My answer here: What is the difference between Javascript, JQuery and Ajax?
I have a class that is fully declared in its constructor
There are no classes in Javascript. . Forget them. You really need to learn some basics of this language in order to use them. This is not Java, although it looks similar.
If you have a Design function , it will instantiate. common methods will be in the prototype chain , and only the specific instance data immediately gets into the function using this keyword .
So, the basic concept of the object will look like this:
// constructor of an instance function MyObject( param1, param2 ) { this.param1 = param1; this.param2 = param2; this.param3 = 32; return this; // [optional] } // Public methods can be called by any instance. // Instances share their prototype object. // The this keyword always points to the current // instance that calls the method. MyObject.prototype.sum = function() { return this.param1 + this.param2 + this.param3; } // refresh should be a shared method, since it // does the same thing on every instance MyObject.prototype.refresh = function() { // do the refresh // ... }
This concept is that there is only one update function in memory. And he can deal with any instance. In addition, if another object inherits from MyObject, the update function will inherit . But in memory there will be one more general update function . And it can deal with any of the parent or child instances.
source share