On Github jden / jseverywhere
Jason Denizac
(although they can help)
function (stuff) { if (!stuff) throw new Error(false); return true; }
function (stuff) { return promise(function () { if (!stuff) this.reject(new Error(false)); this.resolve(true); }) }
f ◦ g (x) - arithmetic
f(g(x)) - synchronous code
g(x).then(f) - promises
users.getUsers({id: 2}, function (err, data) { if (err) { // ? } console.log(data); })
try{ users.getUsers({id: 2}, function (err, data) { if (err) { var newErr = new Error('Unable to load user 2'); newErr.innerError = err; throw newErr; } console.log(data); }) } catch (err) { console.log('Oh no, there was an error:', err); }
users.getUsers({id: 2}).then( function (data) { console.log(data); }, function (err) { console.log('Oh no, there was an error:', err); })
users.getUsers({id: 2}).then( function (data) { console.log(data); }) .then(manipulateSomeData) .then(saveSomeData) .then(null, function (err) { console.log('Oh no, there was an error:', err); })
seperation of concerns: define the interface
I need x, I do y
I don't care when
@leJDen