I have a .js file which has a class defined. I want to call this class from <script> from another html file.
component.js:
class TryClass {
constructor(name) {
this.name = name;
}
sayHi() {
alert( this.name );
}
}
main.html:
<html>
<script src="./component.js" />
<script>
var user = new TryClass( "John" );
user.sayHi();
</script>
<body>
</body>
This doesn't show the alert when I load main.html (from my webserver). However, with the inspect console, I am able to use the TryClass.
How to resolve this?