call to an independent file class with module pattern javascript (edited)












1















I'm not sure I explained myself correctly.
I have a generic class ussed by lots of *.js files
let´s said TestClass.



class TestClass {   

constructor(a,b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a,b)
{
return a+b;
}
}


What I need is to use this "classic" class from several *.js files builded using "module pattern"



//const {moduloTest} = require("scripts/testClass.js"); doesn´t work
even using the answer in
How do I include a JavaScript file in another JavaScript file?



//import{TestClass} from "scripts/testClass.js"; doesn´t work ( even with the extension *.mjs)



example file :



var MyNameSpace = {};
MyNameSpace = (function () {

// global variables
var object1 = new TestClass();

// Private methods
function PrivateMethod () {
console.log("result = ", object1.suma(3,4));
}

// ..........................................................
// public methods
return {
init: function () {},
anotherPublicMethod: function () {}
}
}());


new edition to show how I had already included the call to namespace in a very simple html code



<!DOCTYPE html>
<html lang="en" >

<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>

</head>


<!--here the call.-->
<body onload="moduloTest.init();">
<script src="scripts/ClasePrueba.js"></script>
<script src="scripts/modulePattern.js"></script>

</body>

</html>









share|improve this question

























  • How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

    – Bergi
    Nov 17 '18 at 20:29













  • Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

    – jballes
    Nov 18 '18 at 19:59













  • Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

    – Bergi
    Nov 18 '18 at 20:01











  • yes, in an html page

    – jballes
    Nov 18 '18 at 20:05











  • Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

    – jballes
    Nov 18 '18 at 20:11
















1















I'm not sure I explained myself correctly.
I have a generic class ussed by lots of *.js files
let´s said TestClass.



class TestClass {   

constructor(a,b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a,b)
{
return a+b;
}
}


What I need is to use this "classic" class from several *.js files builded using "module pattern"



//const {moduloTest} = require("scripts/testClass.js"); doesn´t work
even using the answer in
How do I include a JavaScript file in another JavaScript file?



//import{TestClass} from "scripts/testClass.js"; doesn´t work ( even with the extension *.mjs)



example file :



var MyNameSpace = {};
MyNameSpace = (function () {

// global variables
var object1 = new TestClass();

// Private methods
function PrivateMethod () {
console.log("result = ", object1.suma(3,4));
}

// ..........................................................
// public methods
return {
init: function () {},
anotherPublicMethod: function () {}
}
}());


new edition to show how I had already included the call to namespace in a very simple html code



<!DOCTYPE html>
<html lang="en" >

<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>

</head>


<!--here the call.-->
<body onload="moduloTest.init();">
<script src="scripts/ClasePrueba.js"></script>
<script src="scripts/modulePattern.js"></script>

</body>

</html>









share|improve this question

























  • How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

    – Bergi
    Nov 17 '18 at 20:29













  • Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

    – jballes
    Nov 18 '18 at 19:59













  • Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

    – Bergi
    Nov 18 '18 at 20:01











  • yes, in an html page

    – jballes
    Nov 18 '18 at 20:05











  • Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

    – jballes
    Nov 18 '18 at 20:11














1












1








1








I'm not sure I explained myself correctly.
I have a generic class ussed by lots of *.js files
let´s said TestClass.



class TestClass {   

constructor(a,b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a,b)
{
return a+b;
}
}


What I need is to use this "classic" class from several *.js files builded using "module pattern"



//const {moduloTest} = require("scripts/testClass.js"); doesn´t work
even using the answer in
How do I include a JavaScript file in another JavaScript file?



//import{TestClass} from "scripts/testClass.js"; doesn´t work ( even with the extension *.mjs)



example file :



var MyNameSpace = {};
MyNameSpace = (function () {

// global variables
var object1 = new TestClass();

// Private methods
function PrivateMethod () {
console.log("result = ", object1.suma(3,4));
}

// ..........................................................
// public methods
return {
init: function () {},
anotherPublicMethod: function () {}
}
}());


new edition to show how I had already included the call to namespace in a very simple html code



<!DOCTYPE html>
<html lang="en" >

<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>

</head>


<!--here the call.-->
<body onload="moduloTest.init();">
<script src="scripts/ClasePrueba.js"></script>
<script src="scripts/modulePattern.js"></script>

</body>

</html>









share|improve this question
















I'm not sure I explained myself correctly.
I have a generic class ussed by lots of *.js files
let´s said TestClass.



class TestClass {   

constructor(a,b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a,b)
{
return a+b;
}
}


What I need is to use this "classic" class from several *.js files builded using "module pattern"



//const {moduloTest} = require("scripts/testClass.js"); doesn´t work
even using the answer in
How do I include a JavaScript file in another JavaScript file?



//import{TestClass} from "scripts/testClass.js"; doesn´t work ( even with the extension *.mjs)



example file :



var MyNameSpace = {};
MyNameSpace = (function () {

// global variables
var object1 = new TestClass();

// Private methods
function PrivateMethod () {
console.log("result = ", object1.suma(3,4));
}

// ..........................................................
// public methods
return {
init: function () {},
anotherPublicMethod: function () {}
}
}());


new edition to show how I had already included the call to namespace in a very simple html code



<!DOCTYPE html>
<html lang="en" >

<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>

</head>


<!--here the call.-->
<body onload="moduloTest.init();">
<script src="scripts/ClasePrueba.js"></script>
<script src="scripts/modulePattern.js"></script>

</body>

</html>






javascript module-pattern






share|improve this question















share|improve this question













share|improve this question




share|improve this question








edited Nov 19 '18 at 9:25







jballes

















asked Nov 17 '18 at 20:20









jballesjballes

215




215













  • How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

    – Bergi
    Nov 17 '18 at 20:29













  • Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

    – jballes
    Nov 18 '18 at 19:59













  • Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

    – Bergi
    Nov 18 '18 at 20:01











  • yes, in an html page

    – jballes
    Nov 18 '18 at 20:05











  • Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

    – jballes
    Nov 18 '18 at 20:11



















  • How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

    – Bergi
    Nov 17 '18 at 20:29













  • Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

    – jballes
    Nov 18 '18 at 19:59













  • Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

    – Bergi
    Nov 18 '18 at 20:01











  • yes, in an html page

    – jballes
    Nov 18 '18 at 20:05











  • Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

    – jballes
    Nov 18 '18 at 20:11

















How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

– Bergi
Nov 17 '18 at 20:29







How does the other file declare (or export) your MyClass, and how are all these files loaded? Probably you can just write new MyClass and it will work.

– Bergi
Nov 17 '18 at 20:29















Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

– jballes
Nov 18 '18 at 19:59







Im not sure what you mean. Objects are obviously implemented with new, ...even though there was not explicit in the first post. Now there is...

– jballes
Nov 18 '18 at 19:59















Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

– Bergi
Nov 18 '18 at 20:01





Are you running the scripts in node.js, or are you including them in a html page? (Or something else)?

– Bergi
Nov 18 '18 at 20:01













yes, in an html page

– jballes
Nov 18 '18 at 20:05





yes, in an html page

– jballes
Nov 18 '18 at 20:05













Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

– jballes
Nov 18 '18 at 20:11





Im afraid you will recomend me to left this classic style and use the literal object javascript style, ... but it means lots of work. this is why Im asking for this not complete "clean code"

– jballes
Nov 18 '18 at 20:11












1 Answer
1






active

oldest

votes


















1














Interesting question. I had to spent a couple of minutes to figure out how make it work. Sorry for using the old module syntax, I was too lazy to configure webpack, thus I needed an enviroment which would run through VSCode & node. I presume that it would work with the new import / export syntax as well:



The 'Module' file, simplified to serve as minimal example:



module.exports = {
MyNameSpace: (function() {
//global variables
var p1 = 0;

// Private methods
function private() {
return 'whatever';
}

// Public methods
function public() {
p1 += 1;
return p1;
}

return {
public: public
};
})()
};


The file where we import the 'Module':



// Destructurizing is recommended, otherwise we need to call 
// our methods like MyNameSpace.MyNameSpace.init()

const { MyNameSpace } = require("./Module.js");

console.log(MyNameSpace) // public: [Function: public] <-- No private methods or vars!
console.log(MyNameSpace.public()); // 1
console.log(MyNameSpace.public()); // 2
console.log(MyNameSpace.public()); // 3


Edit A code showing how to attach TestClassto global object, so it is accessible by other scripts (no import/export or bundling required):



HTML
The important part is that the script with shared class is loaded first and synchronously. Then, when attached to global object, it is accessible to all others.



<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>
<script src="./TestClass.js"></script>
</head>
<script>
alert(window.testClass.suma(1,2))
</script>
<body>
</body>
</html>


JS



class TestClass {
constructor(a, b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a, b) {
return a + b;
}
}

window.testClass = new TestClass();





share|improve this answer





















  • 1





    OP does not seem to be working in an environment that supports CommonJS modules.

    – Bergi
    Nov 18 '18 at 20:34






  • 1





    Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

    – HynekS
    Nov 18 '18 at 21:44











  • @Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

    – jballes
    Nov 19 '18 at 9:32











  • @HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

    – jballes
    Nov 19 '18 at 9:36











  • I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

    – HynekS
    Nov 19 '18 at 11:18











Your Answer






StackExchange.ifUsing("editor", function () {
StackExchange.using("externalEditor", function () {
StackExchange.using("snippets", function () {
StackExchange.snippets.init();
});
});
}, "code-snippets");

StackExchange.ready(function() {
var channelOptions = {
tags: "".split(" "),
id: "1"
};
initTagRenderer("".split(" "), "".split(" "), channelOptions);

StackExchange.using("externalEditor", function() {
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled) {
StackExchange.using("snippets", function() {
createEditor();
});
}
else {
createEditor();
}
});

function createEditor() {
StackExchange.prepareEditor({
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader: {
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/3.0/"u003ecc by-sa 3.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
},
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
});


}
});














draft saved

draft discarded


















StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355208%2fcall-to-an-independent-file-class-with-module-pattern-javascript-edited%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown

























1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









1














Interesting question. I had to spent a couple of minutes to figure out how make it work. Sorry for using the old module syntax, I was too lazy to configure webpack, thus I needed an enviroment which would run through VSCode & node. I presume that it would work with the new import / export syntax as well:



The 'Module' file, simplified to serve as minimal example:



module.exports = {
MyNameSpace: (function() {
//global variables
var p1 = 0;

// Private methods
function private() {
return 'whatever';
}

// Public methods
function public() {
p1 += 1;
return p1;
}

return {
public: public
};
})()
};


The file where we import the 'Module':



// Destructurizing is recommended, otherwise we need to call 
// our methods like MyNameSpace.MyNameSpace.init()

const { MyNameSpace } = require("./Module.js");

console.log(MyNameSpace) // public: [Function: public] <-- No private methods or vars!
console.log(MyNameSpace.public()); // 1
console.log(MyNameSpace.public()); // 2
console.log(MyNameSpace.public()); // 3


Edit A code showing how to attach TestClassto global object, so it is accessible by other scripts (no import/export or bundling required):



HTML
The important part is that the script with shared class is loaded first and synchronously. Then, when attached to global object, it is accessible to all others.



<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>
<script src="./TestClass.js"></script>
</head>
<script>
alert(window.testClass.suma(1,2))
</script>
<body>
</body>
</html>


JS



class TestClass {
constructor(a, b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a, b) {
return a + b;
}
}

window.testClass = new TestClass();





share|improve this answer





















  • 1





    OP does not seem to be working in an environment that supports CommonJS modules.

    – Bergi
    Nov 18 '18 at 20:34






  • 1





    Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

    – HynekS
    Nov 18 '18 at 21:44











  • @Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

    – jballes
    Nov 19 '18 at 9:32











  • @HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

    – jballes
    Nov 19 '18 at 9:36











  • I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

    – HynekS
    Nov 19 '18 at 11:18
















1














Interesting question. I had to spent a couple of minutes to figure out how make it work. Sorry for using the old module syntax, I was too lazy to configure webpack, thus I needed an enviroment which would run through VSCode & node. I presume that it would work with the new import / export syntax as well:



The 'Module' file, simplified to serve as minimal example:



module.exports = {
MyNameSpace: (function() {
//global variables
var p1 = 0;

// Private methods
function private() {
return 'whatever';
}

// Public methods
function public() {
p1 += 1;
return p1;
}

return {
public: public
};
})()
};


The file where we import the 'Module':



// Destructurizing is recommended, otherwise we need to call 
// our methods like MyNameSpace.MyNameSpace.init()

const { MyNameSpace } = require("./Module.js");

console.log(MyNameSpace) // public: [Function: public] <-- No private methods or vars!
console.log(MyNameSpace.public()); // 1
console.log(MyNameSpace.public()); // 2
console.log(MyNameSpace.public()); // 3


Edit A code showing how to attach TestClassto global object, so it is accessible by other scripts (no import/export or bundling required):



HTML
The important part is that the script with shared class is loaded first and synchronously. Then, when attached to global object, it is accessible to all others.



<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>
<script src="./TestClass.js"></script>
</head>
<script>
alert(window.testClass.suma(1,2))
</script>
<body>
</body>
</html>


JS



class TestClass {
constructor(a, b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a, b) {
return a + b;
}
}

window.testClass = new TestClass();





share|improve this answer





















  • 1





    OP does not seem to be working in an environment that supports CommonJS modules.

    – Bergi
    Nov 18 '18 at 20:34






  • 1





    Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

    – HynekS
    Nov 18 '18 at 21:44











  • @Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

    – jballes
    Nov 19 '18 at 9:32











  • @HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

    – jballes
    Nov 19 '18 at 9:36











  • I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

    – HynekS
    Nov 19 '18 at 11:18














1












1








1







Interesting question. I had to spent a couple of minutes to figure out how make it work. Sorry for using the old module syntax, I was too lazy to configure webpack, thus I needed an enviroment which would run through VSCode & node. I presume that it would work with the new import / export syntax as well:



The 'Module' file, simplified to serve as minimal example:



module.exports = {
MyNameSpace: (function() {
//global variables
var p1 = 0;

// Private methods
function private() {
return 'whatever';
}

// Public methods
function public() {
p1 += 1;
return p1;
}

return {
public: public
};
})()
};


The file where we import the 'Module':



// Destructurizing is recommended, otherwise we need to call 
// our methods like MyNameSpace.MyNameSpace.init()

const { MyNameSpace } = require("./Module.js");

console.log(MyNameSpace) // public: [Function: public] <-- No private methods or vars!
console.log(MyNameSpace.public()); // 1
console.log(MyNameSpace.public()); // 2
console.log(MyNameSpace.public()); // 3


Edit A code showing how to attach TestClassto global object, so it is accessible by other scripts (no import/export or bundling required):



HTML
The important part is that the script with shared class is loaded first and synchronously. Then, when attached to global object, it is accessible to all others.



<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>
<script src="./TestClass.js"></script>
</head>
<script>
alert(window.testClass.suma(1,2))
</script>
<body>
</body>
</html>


JS



class TestClass {
constructor(a, b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a, b) {
return a + b;
}
}

window.testClass = new TestClass();





share|improve this answer















Interesting question. I had to spent a couple of minutes to figure out how make it work. Sorry for using the old module syntax, I was too lazy to configure webpack, thus I needed an enviroment which would run through VSCode & node. I presume that it would work with the new import / export syntax as well:



The 'Module' file, simplified to serve as minimal example:



module.exports = {
MyNameSpace: (function() {
//global variables
var p1 = 0;

// Private methods
function private() {
return 'whatever';
}

// Public methods
function public() {
p1 += 1;
return p1;
}

return {
public: public
};
})()
};


The file where we import the 'Module':



// Destructurizing is recommended, otherwise we need to call 
// our methods like MyNameSpace.MyNameSpace.init()

const { MyNameSpace } = require("./Module.js");

console.log(MyNameSpace) // public: [Function: public] <-- No private methods or vars!
console.log(MyNameSpace.public()); // 1
console.log(MyNameSpace.public()); // 2
console.log(MyNameSpace.public()); // 3


Edit A code showing how to attach TestClassto global object, so it is accessible by other scripts (no import/export or bundling required):



HTML
The important part is that the script with shared class is loaded first and synchronously. Then, when attached to global object, it is accessible to all others.



<!DOCTYPE html>
<html lang="en" >
<head>
<meta charset="UTF-8">
<title> module pattern with testClass. </title>
<script src="./TestClass.js"></script>
</head>
<script>
alert(window.testClass.suma(1,2))
</script>
<body>
</body>
</html>


JS



class TestClass {
constructor(a, b) {
this.a = a || 0;
this.b = b || 0;
}
// methods
suma(a, b) {
return a + b;
}
}

window.testClass = new TestClass();






share|improve this answer














share|improve this answer



share|improve this answer








edited Nov 19 '18 at 11:15

























answered Nov 17 '18 at 23:41









HynekSHynekS

472414




472414








  • 1





    OP does not seem to be working in an environment that supports CommonJS modules.

    – Bergi
    Nov 18 '18 at 20:34






  • 1





    Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

    – HynekS
    Nov 18 '18 at 21:44











  • @Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

    – jballes
    Nov 19 '18 at 9:32











  • @HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

    – jballes
    Nov 19 '18 at 9:36











  • I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

    – HynekS
    Nov 19 '18 at 11:18














  • 1





    OP does not seem to be working in an environment that supports CommonJS modules.

    – Bergi
    Nov 18 '18 at 20:34






  • 1





    Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

    – HynekS
    Nov 18 '18 at 21:44











  • @Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

    – jballes
    Nov 19 '18 at 9:32











  • @HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

    – jballes
    Nov 19 '18 at 9:36











  • I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

    – HynekS
    Nov 19 '18 at 11:18








1




1





OP does not seem to be working in an environment that supports CommonJS modules.

– Bergi
Nov 18 '18 at 20:34





OP does not seem to be working in an environment that supports CommonJS modules.

– Bergi
Nov 18 '18 at 20:34




1




1





Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

– HynekS
Nov 18 '18 at 21:44





Ah, I didn't notice (or was edited?). In that case I would consider attaching MyNameSpace to the global window object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.

– HynekS
Nov 18 '18 at 21:44













@Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

– jballes
Nov 19 '18 at 9:32





@Bergi what Im trying to use is a simply solution, just before the commonJS specifications and NodeJs.Just what is called "revealing module pattern". Should I deduce from your answer that using revealing module pattern I can not call an external file as a class and use its methods?

– jballes
Nov 19 '18 at 9:32













@HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

– jballes
Nov 19 '18 at 9:36





@HynekS with the risk of being too insistent and boring, I have edited the question again to include the html and the way in which I call the namespace from there. Is that what you were referring to?

– jballes
Nov 19 '18 at 9:36













I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

– HynekS
Nov 19 '18 at 11:18





I updated my answer. But honestly, I am not sure what you exactli ask for – I have a feeling that you are trying to solve too many problems at once.

– HynekS
Nov 19 '18 at 11:18


















draft saved

draft discarded




















































Thanks for contributing an answer to Stack Overflow!


  • Please be sure to answer the question. Provide details and share your research!

But avoid



  • Asking for help, clarification, or responding to other answers.

  • Making statements based on opinion; back them up with references or personal experience.


To learn more, see our tips on writing great answers.




draft saved


draft discarded














StackExchange.ready(
function () {
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f53355208%2fcall-to-an-independent-file-class-with-module-pattern-javascript-edited%23new-answer', 'question_page');
}
);

Post as a guest















Required, but never shown





















































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown

































Required, but never shown














Required, but never shown












Required, but never shown







Required, but never shown







Popular posts from this blog

Guess what letter conforming each word

Port of Spain

Run scheduled task as local user group (not BUILTIN)