You question isn't entirely clear, but I assume you have a function that you want to have called as soon as your object has been instantiated. The simplest way to do this is to pass the function as an argument.
Something like:
var Dummy = function(myFunction) {
self = this;
self.render = myFunction; // if you want to be able to call it again later
self.render(); // if you want to call it now
};
var test = new Dummy(function() {
console.log('Make constructor call this method? ');
});
var anotherTest = new Dummy(function() {
console.log("this instance will have a different render function");
});
Now, of course, this can be extended to handle any number of functions passed in:
var Dummy = function(func1, func2) {
// Note: you may want to check the arguments actually are functions
if (func1) {
func1();
}
if (func2) {
func2();
}
}
var test = new Dummy(function() { console.log("1"); },
function() { console.log("2"); });
Or you could pass in an array of functions in the order you want them executed:
var Dummy = function(funcArray) {
for (var i=0; i < funcArray.length; i++) {
funcArray[i]();
}
}
var test = new Dummy([function() { console.log("1"); },
function() { console.log("2"); }]);
Or you could pass in an object with the functions (and names) you want:
var Dummy = function(funcObject) {
if (funcObject.func1) {
funcObject.func1();
}
if (funcObject.func2) {
funcObject.func2();
}
}
var test = new Dummy({ func1 : function() { console.log("1"); },
func2: function() { console.log("2"); });