Skip to content

Instantly share code, notes, and snippets.

@bmaurer
Created February 1, 2017 23:18
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 bmaurer/fe9d8c1f22774ca42fbf83107bc83dba to your computer and use it in GitHub Desktop.
Save bmaurer/fe9d8c1f22774ca42fbf83107bc83dba to your computer and use it in GitHub Desktop.
var logger;
static {
logger = new Logger();
console.log('hi');
}
export function a() {
logger.log("hey");
}
@bmaurer
Copy link
Author

bmaurer commented Feb 1, 2017

@bmaurer
Copy link
Author

bmaurer commented Feb 1, 2017

cc @dominiccooney @domenic @esprehn This is the thing we talked about today for html5 modules.

The idea here is similar to static blocks in Java or C# (https://msdn.microsoft.com/en-us/library/k9x6w0hc.aspx). The idea is that all of the code inside the static {} block would be guaranteed to be executed before any code within the module was executed. As an example:

import { a } from 'a';
console.log('main1');
a();
console.log('main2');

The static block would likely not execute before the main1 log because even though a has been imported, no function inside of it has been used. But it would be guaranteed that inside a() logger is not null because the constructor would at least run before that point.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment