0

【笔记】JS中的call函数

 1 year ago
source link: https://blog.loli.fj.cn/2023/05/13/JS%E4%B8%AD%E7%9A%84call%E5%87%BD%E6%95%B0/
Go to the source link to view the article. You can view the picture content, updated content and better typesetting reading experience. If the link is broken, please click the button below to view the snapshot at that time.

【笔记】JS中的call函数

2023-05-132023-05-14前端学习指北

JS中的call()函数学习笔记

function 函数名() {
...
}

函数名.call();

改变函数的this指向

无形参列表

  • 通过在call()函数中传递对象作为参数,可以将函数的this指向改变为指定的对象
function 函数名() {
...
}

let 对象名 = {
...
};

函数名.call(对象名);

有形参列表

  • 如果函数有形参列表,需要从call()函数的第二个参数开始传递
function 函数名(形参列表) {
...
}

let 对象名 = {
...
};

函数名.call(对象名, 形参列表);

哔哩哔哩——黑马前端


About Joyk


Aggregate valuable and interesting links.
Joyk means Joy of geeK