call, apply, bind
これは作者に読んでもらうための大きな文章です:)
このターゲットをに変更し、関数 を実行します.
このターゲットをに変更し、関数 を実行します. callとの違いは、その論点が並んでいることです. this targetをthisに変更して終了します.関数は実行されません. 使用モード
https://wooooooak.github.io/javascript/2018/12/08/call,apply,bind/
https://www.zerocho.com/category/JavaScript/post/57433645a48729787807c3fd
関数thisをバインドする方法:call、apply、bind
function.call( this target, argument)
このターゲットを
function.apply( this target, [argument])
このターゲットを
function.bind( this target)
const mangojang = {name: 'mangojang'};
const sayName = function(fruit){
console.log(`my name is ${this.name}. I like ${fruit}`);
}
sayName("mango"); // my name is . I like mango
const setThis = sayName.bind(mangojang);
setThis("mango"); // my name is mangojang. I like mango
sayName.call(mangojang,"mango"); // my name is mangojang. I like mango
sayName.apply(mangojang,["mango"]); // my name is mangojang. I like mango
参考文献
https://wooooooak.github.io/javascript/2018/12/08/call,apply,bind/
https://www.zerocho.com/category/JavaScript/post/57433645a48729787807c3fd
Reference
この問題について(call, apply, bind), 我々は、より多くの情報をここで見つけました https://velog.io/@mangojang/call-apply-bindテキストは自由に共有またはコピーできます。ただし、このドキュメントのURLは参考URLとして残しておいてください。
Collection and Share based on the CC Protocol