call to an independent file class with module pattern javascript (edited)
up vote
1
down vote
favorite
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
|
show 3 more comments
up vote
1
down vote
favorite
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
How does the other file declare (or export) yourMyClass
, and how are all these files loaded? Probably you can just writenew MyClass
and it will work.
– Bergi
Nov 17 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 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 at 20:01
yes, in an html page
– jballes
Nov 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 at 20:11
|
show 3 more comments
up vote
1
down vote
favorite
up vote
1
down vote
favorite
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
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
javascript module-pattern
edited 2 days ago
asked Nov 17 at 20:20


jballes
215
215
How does the other file declare (or export) yourMyClass
, and how are all these files loaded? Probably you can just writenew MyClass
and it will work.
– Bergi
Nov 17 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 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 at 20:01
yes, in an html page
– jballes
Nov 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 at 20:11
|
show 3 more comments
How does the other file declare (or export) yourMyClass
, and how are all these files loaded? Probably you can just writenew MyClass
and it will work.
– Bergi
Nov 17 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 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 at 20:01
yes, in an html page
– jballes
Nov 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 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 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 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 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 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 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 at 20:01
yes, in an html page
– jballes
Nov 18 at 20:05
yes, in an html page
– jballes
Nov 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 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 at 20:11
|
show 3 more comments
1 Answer
1
active
oldest
votes
up vote
1
down vote
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 TestClass
to 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();
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
1
Ah, I didn't notice (or was edited?). In that case I would consider attachingMyNameSpace
to the globalwindow
object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.
– HynekS
Nov 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
2 days ago
@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
2 days ago
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
2 days ago
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
up vote
1
down vote
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 TestClass
to 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();
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
1
Ah, I didn't notice (or was edited?). In that case I would consider attachingMyNameSpace
to the globalwindow
object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.
– HynekS
Nov 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
2 days ago
@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
2 days ago
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
2 days ago
add a comment |
up vote
1
down vote
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 TestClass
to 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();
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
1
Ah, I didn't notice (or was edited?). In that case I would consider attachingMyNameSpace
to the globalwindow
object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.
– HynekS
Nov 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
2 days ago
@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
2 days ago
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
2 days ago
add a comment |
up vote
1
down vote
up vote
1
down vote
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 TestClass
to 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();
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 TestClass
to 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();
edited 2 days ago
answered Nov 17 at 23:41
HynekS
318213
318213
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
1
Ah, I didn't notice (or was edited?). In that case I would consider attachingMyNameSpace
to the globalwindow
object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.
– HynekS
Nov 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
2 days ago
@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
2 days ago
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
2 days ago
add a comment |
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
1
Ah, I didn't notice (or was edited?). In that case I would consider attachingMyNameSpace
to the globalwindow
object. It would be reachable for other scripts while still taking benefit of module pattern private / public properties.
– HynekS
Nov 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
2 days ago
@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
2 days ago
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
2 days ago
1
1
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 18 at 20:34
OP does not seem to be working in an environment that supports CommonJS modules.
– Bergi
Nov 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 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 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
2 days ago
@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
2 days ago
@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
2 days ago
@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
2 days ago
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
2 days ago
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
2 days ago
add a comment |
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
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
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function () {
StackExchange.helpers.onClickDraftSave('#login-link');
});
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
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
How does the other file declare (or export) your
MyClass
, and how are all these files loaded? Probably you can just writenew MyClass
and it will work.– Bergi
Nov 17 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 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 at 20:01
yes, in an html page
– jballes
Nov 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 at 20:11