Skip to content

Instantly share code, notes, and snippets.

@selcukcihan
Created April 3, 2020 14:04
Show Gist options
  • Save selcukcihan/1530aaa56b9c189eab8487a5402fbf89 to your computer and use it in GitHub Desktop.
Save selcukcihan/1530aaa56b9c189eab8487a5402fbf89 to your computer and use it in GitHub Desktop.
Native modül kullanımına ön-yüz örneği
<!doctype HTML>
<html>
<head></head>
<body>
<button id="uykuButonu">Uyu</button>
<script type="module" src="./utils.js"></script>
<script type="module" src="./index.js"></script>
</body>
</html>
import {DEFAULT_SLEEP_MILLISECONDS, sleep} from './utils.js'
document.getElementById('uykuButonu').addEventListener('click', async function() {
await sleep();
alert('uyandım');
});
const DEFAULT_SLEEP_MILLISECONDS = 1000;
function sleep(milliseconds) {
return new Promise(resolve =>
setTimeout(resolve, milliseconds || DEFAULT_SLEEP_MILLISECONDS)
);
}
export { DEFAULT_SLEEP_MILLISECONDS, sleep }
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment