jorendorff / js-loaders

Pseudoimplementation of the proposed ES6 module loaders.
54 stars 7 forks source link

What should `new Loader({/* no hooks */});` do? #103

Closed unscriptable closed 10 years ago

unscriptable commented 10 years ago

If a dev constructs a new loader with no hooks (e.g. new Loader({/* no hooks */});), will the loader be functional? Does it take-on some default behavior based on the environment? Or does it throw an exception if you try to import using it?

juandopazo commented 10 years ago

The way it is spec'd right now, hooks override methods in the new Loader instance. So these two are equivalent:

var loader = new Loader({ fetch: fn });

var loader2 = new Loader();
loader2.fetch = fn;

This means that it'll default to Loader.prototype.fetch (which throws). From 26.3.1.1.9:

If hook is not undefined, If isCallable(hook) is false, throw a TypeError exception. Let result be CreatePropertyOrThrow(loader, name, hook).

See http://people.mozilla.org/~jorendorff/es6-draft.html#sec-%loader%.

So yes, it throws.

johnjbarton commented 10 years ago

The environment default behavior is baked into the System instance of Loader, not into the class Loader.

unscriptable commented 10 years ago

thanks guys!