New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[js] js的函数有哪几种调用形式? #908
Comments
fn(arg1, arg2, ...)
fn.call(thisArg, arg1, arg2, ...)
fn.apply(thisArg, [arg1, arg2, ...]) 其中, 同时可以使用 |
直接调用 |
new Xxx(),构造函数调用 |
|
|
如果是问函数自执行的方式有哪些呢? // 1
(func (){
})()
//... |
// 1. 全局调用
function fn(args){}
fn(args)
// 2. 作为对象的属性,以及作为构造函数 new 调用
Obj.prototype.fn = function(args){}
const obj = new Obj()
obj.fn(args)
// 3. call/apply/bind
fn1.call(this, arg1,arg2,...)
fn2.apply(this, [arg1, arg2, ...])
fn3 = fn1.bind(this)
fn3(arg1, arg2, ...1) |
这道题主要是想考察什么了 |
还有 |
总体来说,有四种:① 函数独立调用,直接使用 |
fn() |
js的函数有哪几种调用形式?
The text was updated successfully, but these errors were encountered: