showing results for - "what is call 2c apply 2c bind"
Sofia
01 Nov 2018
1Answer in SIMPLEST form
2
3Call invokes the function and allows you to pass in arguments one by one.
4Apply invokes the function and allows you to pass in arguments as an array.
5Bind returns a new function, allowing you to pass in a this array and any number of arguments.
6
7Apply vs. Call vs. Bind Examples
8--------------
9Call
10
11var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
12var person2 = {firstName: 'Kelly', lastName: 'King'};
13
14function say(greeting) {
15    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
16}
17
18say.call(person1, 'Hello'); // Hello Jon Kuperman
19say.call(person2, 'Hello'); // Hello Kelly King
20
21--------------
22Apply
23
24var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
25var person2 = {firstName: 'Kelly', lastName: 'King'};
26
27function say(greeting) {
28    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
29}
30
31say.apply(person1, ['Hello']); // Hello Jon Kuperman
32say.apply(person2, ['Hello']); // Hello Kelly King
33
34-------------
35Bind
36
37var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
38var person2 = {firstName: 'Kelly', lastName: 'King'};
39
40function say() {
41    console.log('Hello ' + this.firstName + ' ' + this.lastName);
42}
43
44var sayHelloJon = say.bind(person1);
45var sayHelloKelly = say.bind(person2);
46
47sayHelloJon(); // Hello Jon Kuperman
48sayHelloKelly(); // Hello Kelly King
Paola
20 Oct 2019
1const obj = { number: 1 }
2
3function foo() {
4	console.log(this.number)
5}
6
7//bind - binds obj's 'this' context to foo, but doesn't call it
8const newFoo = foo.bind(obj) 
9
10//call/apply - binds obj's 'this' context to foo, then calls it
11foo.call(obj, /*arg1*/, /*arg2*/) 
12foo.apply(obj, [/*arg1*/, /*arg2*/])
13
14//Only difference between call/apply is argument passing - ',' vs '[]'
15
Andrea
31 Jul 2017
1Apply vs. Call vs. Bind Examples
2
3Call
4
5var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
6var person2 = {firstName: 'Kelly', lastName: 'King'};
7
8function say(greeting) {
9    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
10}
11
12say.call(person1, 'Hello'); // Hello Jon Kuperman
13say.call(person2, 'Hello'); // Hello Kelly King
14
15Apply
16
17var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
18var person2 = {firstName: 'Kelly', lastName: 'King'};
19
20function say(greeting) {
21    console.log(greeting + ' ' + this.firstName + ' ' + this.lastName);
22}
23
24say.apply(person1, ['Hello']); // Hello Jon Kuperman
25say.apply(person2, ['Hello']); // Hello Kelly King
26
27Bind
28
29var person1 = {firstName: 'Jon', lastName: 'Kuperman'};
30var person2 = {firstName: 'Kelly', lastName: 'King'};
31
32function say() {
33    console.log('Hello ' + this.firstName + ' ' + this.lastName);
34}
35
36var sayHelloJon = say.bind(person1);
37var sayHelloKelly = say.bind(person2);
38
39sayHelloJon(); // Hello Jon Kuperman
40sayHelloKelly(); // Hello Kelly King
queries leading to this page
call apply bind usage in javascript what 27s the bind 28 29 call 28 29 2c apply 28 29 3fbind call apply es6use call applycall apply bind in javascript with argumentswhat is call 2c apply 2c bindjs call apply bindjavascript bind vs applyjavascript call apply and bindjs apply bind callfnciton call apply bindcall apply bind dow we needcall and apply and bind in javascriptcall apply bind in javascript with argumentcall 2c apply and bindcall apply and bind method in javascriptin what cases we need to use call apply bind in javascript apply call in jscall 28 29 apply 28 29 and bind 28 29 in javascriptbind call applyjavascript built in function call apply bindwhen should we use bind call apply in javascriptcall bind and apply in javascriptcall apply bind exampledifference between call 2c apply and bindjavascript call 2c apply 2c bindw3schools call apply bindexplain how to use call 2c apply and bind methods in javascriptapply 2c call 2c and bindjavascript call bind applyfunction apply bindjavascript function apply call bindhow to implement bind using call and applywhat is call 2c apply and bind 3fwhat is call apply bind method in javascriptdifference between bind call and apply in javascriptwhen to use call bind and applymdn call bind applycall bind and apply in detailcall apply bind in javascript msdnjavascript call apply bind examplecall bind apply in javascript w3schoolsjs bind vs applywhat does apply call and bind do 3fuse of call apply and bind in javascriptwhat is call bind and apply in javascriptcall apply bind methodscall bind apply in javascriptcall apply bind javascriptproject to demonstrate call apply and bind in javascriptbind call apply with examplecall apply bind javascript infojs call 2c apply and bindbind call applywhat is a practical use for call bind apply in javascript 3fbind call apply methods in javascripthow to know where we use call apply and bind method in javascriptjs bind applyjs apply bindwhat is bind apply 26 2a in javascriptjavascript bind and applydoes call 28 29 2cbind 28 29 2c apply 28 29 are using in es6javascript call 28 29 and apply 28 29 vs bind 28 29call apply bind codebind call apply in js11 explain call 28 29 apply 28 29 and bind 28 29 in javascript w3schoolscall 2c bind and applyapply call bind in javascript educbaapply bind callcall apply and bind in javascript w3schoolscall apply bind jscall apply bind in jsthis call apply bindapply and bind in javascriptcall apply bind javascript examplesjs bind or applyapply bind call javascriptunderstanding call apply and bindbind call apply in javascript mdnjavascript call apply bind mndcall apply and bind method in javascript for beginnerscall 2c apply 2c and bindjs concept of call apply bindwhat is call apply bind in javascriptbind apply callwhat does apply call and bind to 3fexplain call 28 29 2c apply 28 29 and 2c bind 28 29 methodscall 28 29 2c apply 28 29 2c and bind 28 29call apply and bind in javascriptcall apply and bind method call apply bindjavascript apply call bindcall bind apply in jsbind 2c call 2c apply in javascriptcall apply bind methods in javascriptcall apply bind bind call apply using this in javascriptcall apply bind js function in domcall apply bind in javascript examplesjs call bind and applyjs bind 2c call or applycall 28 29 2c apply 28 29 and 2c bind 28 29 methods call apply bind in javascript w3schoolsbind call apply javasriptjavascript call 28 29 apply 28 29 bind 28 29apply call bind jsjavascript bind call apply w3schoolscall apply bind definationapply 28 29 call 28 29 and bind 28 29 methodswhy we are using call apply bind java scriptfunction e2 80 99s call 2c apply and bind methodswhat is the use of call apply and bind in javascript practicle usebind call apply in javascriptjs call apply and bindapply 2fbind on callbackhow to use bind and apply in jsapply call bind in javascriptcall bind apply statements in javascriptcall 28 29 apply 28 29 and bind 28 29call apply bind in javascriptwhen to use call apply bindcall bind apply implementationwhat is call 2c apply and bind function in js 3fjs call apply bind w3 schoolscall 2c apply 2c bindwhen should we use bind 2c call and applythis keyword 2c call 2c bind 2c apply in javascript examplecall apply and bindcall bind apply in detailcall 2c apply bind in javascriptcall apply bind javascript w3schoolswhat is bind call apply function in javascriptcall vs apply vs bind in javascriptwhat is call apply bindcalll 2c apply and bind in jscall apply and bind example in javascriptcall bind apply method with examplesbind 2c call 2c apply javascriptthis bind call apply jsbind apply in jsbind apply call javascriptbind applyjavascript this call apply bindcall apply bind in es6this call apply bind javascriptjs function bind call applyjavascript bind apply callcall bind apply jsjvascript bind call applybind apply jshow to bind this to a functionfunction bind and apply in javascriptwhat is the difference between call 2c apply and bind in jscall apply and bind in javascript mdncall apply and bind in jaascriptapply call bindcall 2c bind 2c applywhere we can use apply call and bindimplement your own e2 80 94 call 28 29 2c apply 28 29 and bind 28 29 method in javascriptcalll bind apply jsbind 2c call and apply javascriptcall bind and apply methods javascript infodifference between call and apply and bind in javascriptbind apply javascriptbind apply calllbind and apply javascriptapply bind and call in javascriptbind apply and callbind 2c call 2c applyjs call bind applywhat is apply 2ccall and bindcall 2c apply 2c and bind methodsbind call apply javascriptcall apply bind in javascript mdnthis bind call applyjs bind call applycall 2c apply 2cbind in javascriptcall bind applyhow to use call 2c apply and bindcall apply and bind function in javascriptcall bind anfd apply in javascriptwhy we use call apply and bindapply call bind javascriptdifference between bind 2c call and applycall bind and apply differencejs apply and bindbind apply call example javascript what is bind apply 22call apply bind in javascript 22why call apply bind in javascriptcall apply and bind in jsbind call apply jsbind 2c call and applyhow to use call bind and apply in javascript objectswhat is the different between bind 2c apply and call in javascriptthis call apply bind in jscalll apply bindcall apply bind in js w3call 2c apply and bind javscriptcall apply and bind methods in javascriptbind apply call in javascripthow to really understand call bind and applyexplain call 28 29 2c apply 28 29 and 2c bind 28 29 methods what is the use of call apply and bind in javascriptbind call and apply in jsfunction apply call bindapply bindcall 2capply 2cbind methods in javascript call 28 29 2c apply 28 29 and 2c bind 28 29 methods bind 28 29 jsfunction bind apply calljavascript call bind and applyjavascript call and apply bindjs apply call bindjavascript function apply 28 29 2c bind 28 29 2c call 28 29 tutorialjavascript bind 2c call 2c applycall apply and bind javascriptjavascript call 28 29 apply 28 29 bind 28 29javascript function call apply bindexample of call bind applyapply bind 26 in javascriptbind call and apply in javascriptcall bind apply in javascript with examplecall apply bind definitionwhat is apply call bindwhat is call apply and bind in javascriptjavascript function when to use bind or applyapply call bind in javascript programizjavascript bind call applycall bind apply javascriptcall apply bind w3schoolsapply call bind in javascriptjavascript call apply bindimplement call apply bindreal world use of call 28 29 apply 28 29 bind 28 29 call 28 29 2c apply 28 29 2c bind 28 29js bind apply callcall bind and applyfunction call apply bindapply bind javascriptwhat are call apply and bind methodscall 2c apply 2c bind methodwhat is call 2c apply 2c bind