Skip to content
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

apply的意思理解 #24

Open
xxholly32 opened this issue May 3, 2019 · 0 comments
Open

apply的意思理解 #24

xxholly32 opened this issue May 3, 2019 · 0 comments

Comments

@xxholly32
Copy link
Owner

xxholly32 commented May 3, 2019

定义一个函数mul

function mul(a,b){
    return this+(a*b);
}

接着我们在控制台上打印出

console.log(mul.call(null,2,3));
console.log(mul.call('s',2,3));
console.log(mul.call(3,2,3));
console.log(mul.apply(null,[2,5]));
console.log(mul.apply(2,[2,5]));

分别为:

[object Window]6
s6
9
[object Window]10
12

function.apply(obj, arg)

function(arg) this = obj

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant