en.javascript.info/1-js/06-advanced-functions/10-bind/6-ask-partial/solution.md
2019-08-02 20:18:52 +03:00

437 B

  1. Either use a wrapper function, an arrow to be concise:

    askPassword(() => user.login(true), () => user.login(false)); 
    

    Now it gets user from outer variables and runs it the normal way.

  2. Or create a partial function from user.login that uses user as the context and has the correct first argument:

    askPassword(user.login.bind(user, true), user.login.bind(user, false));