Created
March 12, 2012 20:00
-
-
Save sebmarkbage/2024344 to your computer and use it in GitHub Desktop.
Defered Modules
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 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