Promise - GradedJestRisk/js-training GitHub Wiki

Table of Contents

What is it ?

A promise is not - a function

const aPromise = {
  then: (onFulfilled, onRejected)=>{ onFulfilled({ name: 'toto'})},
};

Idea: https://dorp.io/posts/railway-oriented-programming/

Specs

Specs

const x = await v
v['then'] {return v.then((r)=>{ const x = r }

await/async

hashPassword: (password) => {
  const foo = bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
  return foo.then((value)=>{return value;});
}

hashPassword.then((..));

Same as

hashPassword: async (password) => {
  const foo = await bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
},

Same as

hashPassword: (password) => {
  return bcrypt.hash(password, NUMBER_OF_SALT_ROUNDS);
},

function

const f = () => { a() };
f.foo  =  () => { b()) };

Implemented as
f = {
  _prototype : Function.prototype,
  _body: { a() },
  foo : { b() },
}

f()     => a()
f.foo() => a()

a function

An object with an operator ()

⚠️ **GitHub.com Fallback** ⚠️