I have tried so many things, each and everyone either doesnt work, or breaks another part.
How can I get the following code to work, the requirements are:
- just one instance of the object
- i want to be able to pass in a parameter every time i use the object
- i dont want to pass it/use sub methods, such as getter or setter. not for this specific scenario.
- i want to be able to have private methods
- i want to be able to have public methods
Regarding #5, i have tried with this.func() and prototype.func() but cant get it to work.
I have tried but failed, but think perhaps i need to have a return value? or perhaps self-invoking functions?
below is example/pseudo code of what i have:
var myobj = new function(param){
//code here, able to use input param and private function 'privatefunc' below
var privatefunc=function(){
console.log("i am a private function");
}
this.publicfunc=function(){
console.log("i am a public function");
}
}
myobj("batman");
myobj("superman");
myobj("catwoman");
myobj().publfunc(); // should print out: i am a public function
thank you for your time!