当前位置:网站首页>一个函数有多少种调用方式?
一个函数有多少种调用方式?
2022-08-03 22:22:00 【紫微前端】
在JavaScript中有 4 种方法可以调用函数。调用确定该函数的值或“所有者”对象。this
- 作为函数调用- 如果函数没有作为方法、构造函数或使用
apply
,call
方法调用,则它被作为函数调用。此函数的“所有者”对象将是该window
对象。
//Global Scope
function add(a,b){
console.log(this);
return a + b;
}
add(1,5); // logs the "window" object and returns 6
const o = {
method(callback){
callback();
}
}
o.method(function (){
console.log(this); // logs the "window" object
});
- 作为方法的调用——如果对象的属性具有函数的值,
边栏推荐
猜你喜欢
Embedded systems: overview
目标检测技术研究现状及发展趋势
Data_web(九)mongodb增量同步到mongodb
网络基础学习系列四(网络层,数据链路层和一些其他重要协议或技术)
Flutter 桌面探索 | 自定义可拖拽导航栏
[N1CTF 2018]eating_cms
如何基于WPF写一款数据库文档管理工具(二)
113. 授人以渔 - 如何自行查询任意 SAP UI5 控件属性的文档和技术实现细节
《数字经济全景白皮书》金融数字用户篇 重磅发布!
navicat 连接 mongodb 报错[13][Unauthorized] command listDatabases requires authentication
随机推荐
466. Count The Repetitions
Gains double award | know micro easily won the "2021 China digital twin solution suppliers in excellence" "made in China's smart excellent recommended products" double award!
CAS:908007-17-0_Biotin-azide _生物素叠氮化物
Teach a Man How to Fish - How to Query the Properties of Any SAP UI5 Control by Yourself Documentation and Technical Implementation Details Demo
UVa 1025 - A Spy in the Metro (White Book)
Internet user account information management regulations come into effect today: must crack down on account trading and gray products
目标检测的国内外研究现状
Zilliz 2023 秋季校园招聘正式启动!
win10系统下yolov5-V6.1版本的tensorrt部署细节教程及bug修改
386. Lexicographical Numbers
嵌入式开发:嵌入式基础——代码和数据空间揭秘
L2-041 插松枝
中国企业构建边缘计算解决方案的最佳实践
L2-029 特立独行的幸福
云计算国内外发展现状
数据一致性:双删为什么要延时?
pikachu Over permission
472. Concatenated Words
YOLO之父宣布退出CV界,坦言无法忽视自己工作带来的负面影响
376. Wiggle Subsequence