Skip to content

Instantly share code, notes, and snippets.

@bassjacob
Last active September 28, 2017 00:27
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 bassjacob/52f4276143ccacd9e6b856006b2ec1b3 to your computer and use it in GitHub Desktop.
Save bassjacob/52f4276143ccacd9e6b856006b2ec1b3 to your computer and use it in GitHub Desktop.
Stdlib example
// in your library
const ArrayImpl = {
sum: els => els.reduce((p, c) => p + c),
};
const ObjectImpl = {
map: (f, obj) => Object.keys(obj).reduce((p, c) => Object.assign(p, { [c]: f(obj[c]) }), {}),
};
module.export = {
Array: Object.assign(ArrayImpl, Array), // probably need to do some more to assign symbols etc.
Object: Object.assign(ObjectImpl, Object),
};
// in your runtime
const { Array } = require('stdlib.js'); // Array has all the methods of Array, plus your library methods
// ... use as you would with no danger of breaking a non-you library
// if tc39 ever add a conflicting API, you can instead change the name of the import
// and refactor behind the scenes without breaking your own userland
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment