MyClass = function() {
var init = function() {
console.log("Initializing");
}
this.init();
}
var myInstance = new MyClass();
When I run the above I get
TypeError: Object [object Object] has no method 'init'
It's because by declaring init as a var, or a local variable rather than a property of the object. As such, init does not become a member function of your object, which is why your code failed to run as you expected. Initialize it as this.init = function() { instead to achieve the expected behaviour.