Open blakek opened 7 years ago
Looking back, I'm wondering how this would best be implemented. Fetching the package should be done asynchronously, and the example I wrote above won't work.
My first thought is to use a promise:
var require = window.addtopage.require
require('moment').then(function() {
moment.format('dddd')
})
However, this is targeting browser environment, so we would probably need to either use a fake promise or use a lightweight polyfill. Further, using "require" for the function name may be odd since require() runs "synchronously" in Node.js.
I want to use as a sort of ponyfill for
require
to be able to require libraries from, e.g. npm, for super-lazy prototyping.Example behavior: