「JavaScript」callメソッドを使用するサンプル

環境
Windows 10 64bit Home
Google Chrome 103.0.5060.114

構文
Function.prototype.call()
call() メソッドは、 this の値と、独立して提供された引数によって関数を呼び出します。

使用例

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
const obj = {
str: 'study skill'
}
function funA(){
console.log(this.str);
}
funA.call(obj);
const obj = { str: 'study skill' } function funA(){ console.log(this.str); } funA.call(obj);
const obj = {
    str: 'study skill'
}

function funA(){
    console.log(this.str);
}

funA.call(obj);

実行結果
> “study skill"

JavaScript

Posted by arkgame