Do not define methods in the constructor - this means defining them every time an instance is created. Use Control.prototype.foo = function() {} instead. Also, you do not need to return this if you are using the new operator β the whole point of the new operator.
Recommended Approach:
function MyClass(param1) {
To understand this code, you need to understand the javascript prototype-based inheritance model. When you create an instance of MyClass, you get a new object that inherits any properties that are present in MyClass.prototype . More on this
I also wonder:
A function is a controller and has just been declared once.
If you do not use this several times, you do not need to create something like a class. You can do this instead:
var control = {doSomething:function() { ... }};
I assume that you are used to Java, where everything should be a class, regardless of whether it makes sense or not. Javascript is different, you can also create individual objects or functions as needed.
source share