Reputation: 32913
I am using following code which uses prototypal inheritance. Somehow when I create a new instance of ModuleA
then it return
Uncaught ReferenceError: ModuleA is not defined
Below is my code
(function () {
var ModuleA = function () {
console.log('ModuleA');
};
ModuleA.prototype = (function () {
var moduleA = function () {
};
return {
moduleA: moduleA
}
}());
return ModuleA;
})();
new ModuleA();
UPDATE
Upvotes: 0
Views: 31
Reputation: 1377
It's because you explicitely put your ModuleA declaration in an IIFE which will hide everything inside. So ModuleA is in the scope of your IIFE. You did return return ModuleA
but you didn't put it anywhere.
Do this instead :
var ModuleA = (function () {
var ModuleA = function () {
console.log('ModuleA');
};
ModuleA.prototype = (function () {
var moduleA = function () {
};
return {
moduleA: moduleA
}
}());
return ModuleA;
})();
new ModuleA();
Upvotes: 1