Created
September 19, 2020 23:56
-
-
Save shizuka-na-kazushi/d2fedf9e24d45808eca9c6807295ee21 to your computer and use it in GitHub Desktop.
関数呼び出しをapplyハンドラとProxyで置き換える
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 元の関数を定義 | |
function showtime(season) { | |
console.log(`トムとジェリーのシーズン ${season}をみる`); | |
} | |
// 元の関数を呼び出し | |
showtime(1); | |
showtime(2); | |
showtime(3); | |
// ハンドラー (apply)を定義し、元の関数を新しいパラメータで呼び出す | |
var handler = { | |
apply: (target, thisArg, argumentsList) => { | |
return target(59); | |
} | |
}; | |
// 元の関数とhandlerを引数にProxyを生成 | |
showtime = new Proxy(showtime, handler); | |
// proxyで置き換えた関数を呼び出す | |
showtime(1); | |
showtime(2); | |
showtime(3); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment