Skip to content

Instantly share code, notes, and snippets.

@sebmarkbage
Created March 12, 2012 20:00
Show Gist options
  • Save sebmarkbage/2024344 to your computer and use it in GitHub Desktop.
Save sebmarkbage/2024344 to your computer and use it in GitHub Desktop.
Defered Modules
// Deferred Labeled Modules.js
require: 'Foo';
function LoadSomething(){
var a = 'A'; // Synchronous
alert('Will now start loading the Foo module');
defer: {
a = ImportedFromFoo(a); // The module 'Foo' is optionally deferred asynchronously, because the binding is only used here
alert('Done');
}
}
// Deferred Labeled Modules - Desugared.js
function LoadSomething(){
var a = 'A';
alert('Will now start loading the Foo module');
PRELOAD_MODULE('Foo', function(){
a = require('Foo').ImportedFromFoo(a);
alert('Done');
});
}
// ES.next syntax?
function LoadSomething(){
var a = 'A'; // Synchronous
alert('Will now start loading the Foo module');
defer { // Asynchronous
import * from 'Foo';
a = ImportedFromFoo(a); // Possible optimization problem, late binding scoped variable
alert('Done');
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment