Skip to content

Instantly share code, notes, and snippets.

@leadVisionary
Created February 21, 2018 03:49
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 leadVisionary/03aa70c870271724d1690d82512301e8 to your computer and use it in GitHub Desktop.
Save leadVisionary/03aa70c870271724d1690d82512301e8 to your computer and use it in GitHub Desktop.
Working ECMAScript modules
<html>
<head>
<title>An E-commerce retailer</title>
</head>
<body>
<h1> Hello <span id="greeting">Placeholder</span>!</h1>
<h2> Please <a href="buy/12345">buy</a> this product</h2>
</body>
<script src="greeting.js" type="module"></script>
<script type="module">
import greetCustomer from './greeting.js'
greetCustomer(document.querySelector("#greeting"));
</script>
</html>
import getUserPreferredLanguage from './language.js'
import crossPlatformSpanTextUpdate from './cross_platform_span_update.js'
export default function greetCustomer(location) {
loadGreeting(location, getUserPreferredLanguage());
}
function loadGreeting(span, lang) {
var text = greeting(lang);
crossPlatformSpanTextUpdate(span, text);
}
function greeting(lang) {
if (lang === "es") {
return "Dear dear Customer";
}
return "Valued Shopper";
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment