Reputation: 2317
I have a simple javascript prototype object, with a function defined. Is it possible to have the function invoked when constructing the prototype?
Any help would be really appreciated. Thank you in advance!
function Proto(){
function invoke(){
console.log("I am invoked");
}
}
var proto = new Proto()
Upvotes: 0
Views: 82
Reputation: 2274
You could make it an IIFE:
function Proto(){
(function invoke(){
console.log("I am invoked");
})();
}
Or you could just call it in the constructor function:
function Proto(){
function invoke(){
console.log("I am invoked");
}
invoke();
}
var proto = new Proto()
Upvotes: 4