4
【笔记】JS函数的定义和调用
source link: https://blog.loli.fj.cn/2023/05/13/JS%E5%87%BD%E6%95%B0%E7%9A%84%E5%AE%9A%E4%B9%89%E5%92%8C%E8%B0%83%E7%94%A8/
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函数的定义和调用
2023-05-132023-05-14前端学习指北
JS函数的定义和调用学习笔记
function 函数名(形参列表) {
...
}
const 变量名 = function(形参列表) {
...
};
通过构造函数
- 所有其他的函数都是
Function()
构造函数的实例 - 通过
new Function()
创建的函数也是对象,因为这个对象也有__proto__
属性,在Javascript中也是万物皆对象
不包含形参
const 变量名 = new Function("函数体");
const 变量名 = new Function("形参1", "形参2", ..., "函数体");
函数的调用
函数名();
通过call()函数调用
函数名.call();
调用对象中的方法
对象名.方法名();
通过new调用构造函数
new 构造函数名();
绑定事件的函数
对象名.onclick = function() {
...
}
定时器自动执行的函数
setInterval(function() {
...
}, 1000);
自调用的函数
(function() {
...
})();
Recommend
About Joyk
Aggregate valuable and interesting links.
Joyk means Joy of geeK