Here is my module:
MyModule = (function () {
var myModule = function MyModule(strInput) {
if (false === (this instanceof MyModule)) {
return new MyModule();
}
var str = strInput;
this.getStr = function () {
return str;
}
this.test = function () {
var testModule = new MyModule("testInside");
return testModule;
}
}
return myModule;
}());
Here is how I test my module:
document.getElementById("Button").onclick = function () {
var module = new MyModule("input");
var module2 = module.test();
console.log(module2.getStr());
console.log(module.getStr());
}
This code returns:
testInside
testInside
to the console.log, but what I expect is:
testInside
input
like I do in c# or java when I build a new class inside the same class.
Thanks in advance for your help.
i don’t know what exactly i did, just got it by fluke. But please, don’t confuse the reader by using MyModule twice. Anyways, this is all i did:
UPDATE:
there’s a simpler solution. I just copy-paste-edited your code so there wasn’t much variation. This is the simplest one: