Skip to content

Instantly share code, notes, and snippets.

View lukehoban's full-sized avatar

Luke Hoban lukehoban

View GitHub Profile
@lukehoban
lukehoban / gist:1625486
Created January 17, 2012 07:40
AMD using ES6 module loaders
/*
// The default system module loader exposed by ES6 on the
// global object.
Object.system = {
load: function(name, callback, errback) {
// ...
},
loaded: {}
}
*/
@lukehoban
lukehoban / gist:2246758
Created March 30, 2012 05:17
ES6 module loader API polyfill experiment
(function (global) {
// TODO: Delegate to parent loader in various places
// TODO: Canonicalization
// TODO: Can we do better for 'eval'?
/// Module loader constructor
function Loader(parent, options) {
// Initialization of loader state from options
@lukehoban
lukehoban / gist:3137947
Created July 18, 2012 18:33
const questions
//#1
// Current spec would suggest that this is an early error during compilation of the main code.
// However, dynamically, the "x=20" will write to the "var x" declared inside g.
// This is a case where the early error for assignments to const variables appears to overreach, flagging an error which will not actually occur if the code were allowed to run.
function f() {
const x = 5;
function g() {
eval(“var x = 10”);
x = 20;
}
@lukehoban
lukehoban / gist:3900992
Created October 16, 2012 18:11
ES6 module syntax alternatives
Things I want to be able to do:
a) Bind a name to a remote module
b) Alias a name for a module
c) Alias a name for a member of a remote module
d) Put all names from inside a module in lexical scope
e) Put all names from inside a remote module in lexical scope
f) Put a few names from inside a module in lexical scope
g) Define a local module
h) Export names from lexical scope
i) Re-export names from other modules
@lukehoban
lukehoban / gist:4093199
Created November 17, 2012 04:06
Creating a Blob from a Windows IBuffer or RandomAccesStream
// If you are starting with a file from a picker, something like this should work:
var picker = new Windows.Storage.Pickers.FileOpenPicker();
picker.fileTypeFilter.replaceAll(['.jpg', '.jpeg']);
picker.pickSingleFileAsync().then(function (file) {
return file.openAsync(Windows.Storage.FileAccessMode.read);
}).done(function (ras) {
var blob = MSApp.createBlobFromRandomAccessStream('image/jpeg', ras);
// Spawn function inspired by Q.async at http://wiki.ecmascript.org/doku.php?id=strawman:async_functions#reference_implementation
// Takes an ES6 generator function and produces a WinJS.Promise
function spawn(generatorFunc) {
return new WinJS.Promise(function (c, e) {
var generator = generatorFunc();
var callback = continuer.bind(void 0, 'send');
var errback = continuer.bind(void 0, 'throw');
function continuer(verb, valueOrErr) {
var promisedValue;
@lukehoban
lukehoban / yield.md
Created January 28, 2014 23:00
Precedence of `yield` in ES6
// Current ES spec grammar
1 + yield //  error
1 + yield 2 //  error
yield + 1 // yield (+1)
yield 1 + yield 2 // error
yield(1) + yield(2) // error
yield 1 + 2 // yield (1+2)
yield * yield // (yield *) yield
yield + yield // error
@lukehoban
lukehoban / compile.js
Last active August 29, 2015 13:56
Compiling source text with TypeScript compiler API
// Using bin/typescript.js from TypeScript 0.9.7
function compile(source) {
var parseErrors = [];
var logger = new TypeScript.NullLogger();
var compilationSettings = TypeScript.ImmutableCompilationSettings.defaultSettings();
var compiler = new TypeScript.TypeScriptCompiler(logger, compilationSettings);
var snapshot = TypeScript.ScriptSnapshot.fromString(source);
@lukehoban
lukehoban / 0_reuse_code.js
Created March 2, 2014 07:00
Here are some things you can do with Gists in GistBox.
// Use Gists to store code you would like to remember later on
console.log(window); // log the "window" object to the console
@lukehoban
lukehoban / javascript_resources.md
Created March 2, 2014 07:00 — forked from jookyboi/javascript_resources.md
Here are a set of libraries, plugins and guides which may be useful to your Javascript coding.

Libraries

  • jQuery - The de-facto library for the modern age. It makes things like HTML document traversal and manipulation, event handling, animation, and Ajax much simpler with an easy-to-use API that works across a multitude of browsers.
  • Backbone - Backbone.js gives structure to web applications by providing models with key-value binding and custom events, collections with a rich API of enumerable functions, views with declarative event handling, and connects it all to your existing API over a RESTful JSON interface.
  • AngularJS - Conventions based MVC framework for HTML5 apps.
  • Underscore - Underscore is a utility-belt library for JavaScript that provides a lot of the functional programming support that you would expect in Prototype.js (or Ruby), but without extending any of the built-in JavaScript objects.
  • lawnchair - Key/value store adapter for indexdb, localStorage