Open ndorf opened 5 years ago
Hi Nathan, I'm not sure I follow. Could you please elaborate?
Why should one ever have to type var anything = ...
in JavaScript when a perfectly good callback interface can exist instead?
The ideal scenario would of course be `require('callbax', module => { module.isArray(...) }) but since that's built into JS, the least you could do is have the module's exports take callbacks. I mean come on.
Speaking of which, how would you feel about a lightly patched V8 engine appearing as a PR in this repo?
Ah I understand now, and you make some good points. How does the API prevent this usage though? Could you provide an example of how lib/add.js
should look?
As for require, we could simply redefine the require function. I think that would be within the scope of this project since #7 is also on our roadmap.
This works:
global.__require = require.bind();
global.require = require = function require(...args) {
if (args.length === 1) return __require(args[0]);
return args[1](null, __require(args[0]));
};
// Test:
require('callbaxx', function (err, callbaxx) {
callbaxx.map([5, 15, 25, 35], callbaxx.add, function (e, r) {
console.log(r);
}, true, 5);
});
Beautiful.
Shouldn't this
be more like
?