当前位置:网站首页>Differences among apply, call, and bind in JS
Differences among apply, call, and bind in JS
2022-07-27 05:41:00 【weixin_ forty-six million fifty-one thousand two hundred and si】
1)apply: Two parameters , The first is this Point to , The second is the parameters accepted by the function , Pass in as an array
2)call: Two parameters , The first is this Point to , The second is the parameter list
3)bind: Two parameters , The first is this Point to , The second is the parameter list , change this Pointing will not be executed immediately , Return to a permanent change this Function pointed to
If this Pointing to undefined, So it actually points to windows
function fun(...arguments) {
console.log(this);
console.log(...arguments);
}
var person = {
name: 'jack'
}
console.log('--------------------');
fun.apply(person, [1, 2, 3, 4, 5])
fun(1, 2, 3, 4, 5)
fun.apply(null, [1, 2])
fun.apply(undefined, [1, 2])
console.log('--------------------');
fun.call(person, 1, 2, 3, 4, 5)
fun(1, 2, 3, 4, 5)
fun.call(null, 1, 2)
fun.call(undefined, 1, 2)
console.log('--------------------');
var bindFun=fun.bind(person, 1, 2, 3, 4, 5)
bindFun()
var bindFun1=fun.bind(undefined,1,2)
bindFun1()

this Point to the situation “
1) Call... As a function ,this It's always window
2) Call... As a method ,this It's the object that calls the method
3) Call... As a constructor (new),this It's the newly created object
4) Use call and apply Invocation time ,this It's the designated object
边栏推荐
猜你喜欢

Graph-node部署及测试

「PHP基础知识」PHP中的注释

JS中apply、call、bind的区别

「PHP基础知识」整型数据的使用

Configure the route and go to the login home page to send the request

页面的基本布局

Share a multiple-choice question about variables (including global variables, local variables, the scope of variables, and life cycle knowledge points)

权限的配置,组件传值

First knowledge of C language - string + escape character + comment

Share a multiple-choice question about the process of program compilation (including a brief discussion on the compilation process, the formation and merging process of symbol tables)
随机推荐
Return value of & (and) and | (or) operators in JS
[NPUCTF2020]ReadlezPHP 1
First acquaintance with C language - first acquaintance with pointer
Dimitra 和 Ocean Protocol 解读农业数据背后的秘密
Construction of layout and display of weather forecast
SeekTiger即将上线STI聚变Mining功能,获取OKA通证
权限的配置,组件传值
弹性盒/伸缩盒(flex)的使用
Ubuntu:安装PostgreSQL
Introduction to C language pointer
攻防世界-mfw
User login - and create and verify SMS verification code
[C language switch branch statement and loop statement]
arguments
JS中forEach和map方法有什么区别
binglog备份数据
Configure the route and go to the login home page to send the request
[CISCN2019 华东南赛区]Web11 1
进制的特性
js基础练习题