Last active
September 28, 2017 00:27
-
-
Save bassjacob/52f4276143ccacd9e6b856006b2ec1b3 to your computer and use it in GitHub Desktop.
Stdlib example
This file contains hidden or 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
// 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