Skip to content

Instantly share code, notes, and snippets.

@sdkfz181tiger
Last active December 16, 2022 01:44
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sdkfz181tiger/68d5e6d9f2a58122948c3f755e105c01 to your computer and use it in GitHub Desktop.
Save sdkfz181tiger/68d5e6d9f2a58122948c3f755e105c01 to your computer and use it in GitHub Desktop.
Module基礎
import { myName, myFunc, MyModule } from "./custom_module.js";
$(document).ready(()=>{
console.log("Ready!!");
// Variable
console.log(myName);
// Function
myFunc();
// Class
const myModule = new MyModule();
myModule.sayHello();
myModule.sayByebye();
myModule.saySomething("#my_area", "Hello, Module!!");
});
export { myName, myFunc, MyModule };
const myName = "Hoge!!";
const myFunc = ()=>{
console.log("Fuga!!");
}
class MyModule{
constructor(){
console.log("MyModule");
}
sayHello(){
console.log("Hello!!");
}
sayByebye(){
console.log("Byebye!!");
}
saySomething(selector, txt){
$(selector).text(txt);
}
}
<!DOCTYPE html>
<html lang="ja">
<head>
<meta charset="UTF-8"/>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="shortcut icon" href="./images/favicon.ico">
<title>Module</title>
</head>
<body>
<div id="my_container">
<div>
<div>= Module =</div>
<div id="my_area">***</div>
</div>
</div>
<!-- JavaScript -->
<script src="//code.jquery.com/jquery-3.6.1.min.js"></script>
<script src="./custom_main.js" type="module"></script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment