User.js
export default class User
{
constructor()
{
this.Name;
this.Email;
}
}
index.html
<!DOCTYPE html>
<html lang="en">
<head>
<title>Document</title>
</head>
<body>
<div>
<p>Index Page</p>
<button onclick="AlertFunction()">Click</button>
</div>
</body>
<script type="text/javascript" src="index.js"></script>
</html>
index.js
import User from './Modules/User.js';
let thisUser = new User();
thisUser.Name = 'Javascript';
console.log(thisUser.Name);
function AlertFunction()
{
alert('Alert Clicked');
}
Actual problem: AlertFunction() is not working after the import statement. I want to use class User Type in multiple .js files.
I want to write Util class in Javascript and use it for various files inside my project. I am new to Javascript. Before now I was a .net developer.
In .net we can access all .cs (cSharp files) in the environment. We can access it as a new type for the entire project. We don't need import statements.
But, here in the javascript please help me to understand how import works.