3 ms·
[JavaScript] to promise or to callback? This is the problem
- mc_hammer 11y agopromise and cb are poor design imo. promises are unnecessarily complex, promises replace this paradigm: data = foo() bar(data) both could be probably be replaced by a new keyword (if we make compilers a tad smarter) foo = fn1() bar = fn2() await foo,bar baz() callbacks definitely have there place but should not be used for returned databases query et al, execpt for transforming the data like a middleware: db.query(..., datatransformfn)
- mchahn 11y agoHmm. If every library author took the second approach there would be tons of wasted code. This may not be a bad thing but it bothers my OCD. It would be nice if you could write callback-only or promise-only code and have a post-processor produce two .JS files. One with callbacks and one with promises. Then somehow, just as magically, you could require either one. This would save memory and my OCD.