0
0

More than 3 years have passed since last update.

javascriptで関数をwrapする

Posted at

javascriptで関数をwrapしたいときー
例えば、非同期処理の完了を待つまでなんかしたいときとか

const wrapper = function(func) {
    /*** なんか処理 ***/
    let result = func();
    /*** なんか処理 ***/
};

async/awaitバージョン

const wrapper = async function(func) {
    /*** なんか処理 ***/
    let result = await func();
    /*** なんか処理 ***/
};

普通ですね

つかうときー

// 引数を取らない関数の場合
wrapper(funcA)

// 引数を取る関数の場合 ここが特殊!
wrapper(funcB.bind(null, "unko"))
0
0
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
0