I am new to Javascript and I use Visual Code as the IDE for working with Javascript.
I am learning some lessons, and I ran into a problem that I cannot solve it.
I use module.export to export my js file and I use it to use it in the main file. However, it does not work, as I expect a warning message to appear.
Below is my code
**task.js**
'use strict';
class Task {
constructor(name) {
this.name = name;
}
completed() {
alert(this.name);
}
}
module.export = Task;
**cat.js**
'use strict';
function Cat(name) {
this.name = name;
this.toString = function() {
alert(name);
};
}
Cat.prototype.complete = function() {
console.log('Completed');
};
module.export = Cat;
**main.js**
var Task = require('./task');
var Cat = require('./cat');
var task1 = new Task("A");
task1.completed();
var cat1 = new Cat("Fluffy");
cat1.toString();
cat1.complete();
**Demo1.html**
<!DOCTYPE html>
<html>
<head>
</head>
<body>
<h1> Hello! </h1>
<p id="demo"></p>
<script type="text/javascript" src="script/main.js"></script>
</body>
</html>
Directory structure:
.vscode
script
cat.js
task.js
main.js
demo1.html
I do not get errors on the output console. Any help would be greatly appreciated.
source
share