Here I attempted to create a package called com.matogen.ght with a class in it, Calendar. I’d like the init() method to be called automatically when I instantiate the calendar object. The example below works, but I still have to explicitly call the init() method.
var com = {
matogen : {
ght : {
'Calendar' : function() {
this.init = function() {
console.log("This is my constructor");
}
}
}
}
}
$(document).ready(function() {
var cal = new com.matogen.ght.Calendar();
cal.init();
});
just change your
initfunction like sowith a self executed anonymous function or, if you prefer, just call the function itself like so