当前位置:网站首页>js的call、apply、bind
js的call、apply、bind
2022-07-23 05:39:00 【Vivqst】
Function.prototype.call(thisArg,arg1,arg2)
使用一个指定的 this 值和单独给出的一个或多个参数来调用一个函数
Function.prototype.apply(thisArg,[arg1, arg2])
调用一个具有给定this值的函数,以及以一个数组(或类数组对象)的形式提供的参数
用途与call()类似,区别是接收的参数不一样,call接收参数列表,apply接收参数数组
function Person(name, age) {
this.name = name
this.age = age
this.greeting = function() {
console.log(this.name + ' is ' + this.age)
}
}
function Teacher() {
// Person.call(this, 'lisi', 18)
Person.apply(this, ['lisi', '18'])
this.subject = '语文'
}
var teacher = new Teacher()
var person = new Person('张三', '15')
person.greeting() // 张三 is 15
teacher.greeting() // lisi is 18
Function.prototype.bind(thisArg,arg1,arg2)
bind() 方法创建一个新的函数,在 bind() 被调用时,这个新函数的 this 被指定为 bind() 的第一个参数,而其余参数将作为新函数的参数,供调用时使用。
边栏推荐
猜你喜欢

MySQL statement queries all child nodes of a level node

WebSocket长连接

牛客刷题记录--Mysql

Five methods to prevent over fitting of neural network

大厂面试机器学习算法(0):特征工程 | 数据预处理

Spark common interview questions sorting
![[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用](/img/6f/e6f5ef79c232d9b27a8334cd8ddaa5.png)
[Hudi]hudi的编译及hudi&spark和hudi&flink的简单使用
![[pytho-flask筆記5]藍圖簡單使用](/img/0a/00b259f42e2fa83d4871263cc5f184.png)
[pytho-flask筆記5]藍圖簡單使用

Machine learning algorithm for large factory interview (6) time series analysis

初识Flask
随机推荐
对NLP中transformer里面decoder的理解
Markdown常用语法记录
人脸识别神经网络实现
Pywinauto+某应用程序(学习至第9讲)--受阻
Flask蓝图
Pycharm occupies C disk
项目部署(简版)
项目流程总结
初识Flask
Master slave synchronization step read / write separation + self encountered error sharing
Leetcode daily question (1946. largest number after varying substring)
DWI图像 从DICOM Tag识别 b value 的方法
[pytho-flask笔记5]蓝图简单使用
Fun code rain, share it online~-
mysql语法(纯语法)
When using cache in sprintboot, the data cannot be loaded
知识点回顾
Cell sends SMS asynchronously
大厂面试机器学习算法(6)时间序列分析
Project deployment (simplified version)