Skip to content

Instantly share code, notes, and snippets.

@sjmiles
Last active August 29, 2015 14:02
Show Gist options
  • Save sjmiles/af9d353690758ac9ee42 to your computer and use it in GitHub Desktop.
Save sjmiles/af9d353690758ac9ee42 to your computer and use it in GitHub Desktop.
// irand.html
<script>
modularize(function() {
// whatever we return constitutes our `module`
return function(n) {
return Math.floor(Math.random() * n);
}
});
</script>
// text.html
<!-- imports handle dependency management and network access -->
<link rel="import" href="irand.html">
<script>
// create a module that uses 'irand'
modularize(['irand'], function(irand) {
// whatever we return constitutes our `module`
return {
get text() {
return ['Ahoy-hoy', 'Excellent', 'Gyrocopter to Siam'][irand(3)];
}
}
});
</script>
// index.html
<link rel="import" href="text.html">
<script>
using(['text'], function(text) {
document.write(text.text);
});
</script>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment