javaScript call apply and bind




How To Use .call(), .apply() and .bind() In Javascript. Learn by code examples.

javascript call apply bind
javascript call and apply
javascript call method
call function
javascript call vs apply vs bind
js call() & apply() vs bind()?
How To Use .call(), .apply() and .bind() In Javascript
how apply and call functions work in javascript
javaScript tutorials, javaScript lessons , javaScript training
java Script tutorials, java Script lessons , java Script training
JS tutorials, JS lessons , JS training

Original source


28 responses to “javaScript call apply and bind”

  1. How do these relate to prototypes? Is prototyping something akin to inline 'bind'? BTW: This is how classic OO works: someFunction(this,arg1,arg2) — in OO the 'this' is actually being hidden to the caller but it's there.

  2. Hi techsith, That's an awesome tutorial …it was clear enough …..But I have a question about it's application…..My question is ," we can simply make an object by invoking a constructor and then if we want common method to use we can simply add a prototype method of that object…..so why do we need to use this call, bind apply method?"

  3. console.log("Demo of apply()");
    var obj=100;

    var fnAdd2This=function(a,b,c,d)
    {
    return a+b+c+d;
    }

    var arr=[{fname:'abhi'},{fname:'abhijeet'},{fname:'abhishek'},{fname:'abhilasha'},{fname:'abhimaan'}];
    //here consider Nth number of elements in array .we cant count it
    var arr4nums=[1,2,4,5,10];//this array have Nth elements
    console.log('-apply——>'+fnAdd2This.apply(obj,arr4nums));

    My Quiz is –>Here consider Nth number of elements in array(arr4Nums),Its an dynamic array in that case how we can count the parameters, pass the parameter to fnAddToThis()

  4. Hi,

    thanks for the video, I understand the basic difference among them, but tell me where will use this in real world. Can you post me any real time example that makes more sense. Thanks in advance

  5. Thanks this part is very much clear.
    i have seen the following process, please tell me what is going on this process:

    (function(){
    function test(){
    return 21;
    }
    }).call();

    Here, call method is written without arguments. (might use apply also instead of call)

  6. There is one aspect of .call(), .apply() and .bind() that you perhaps could have emphasized a bit more, namely: Whenever you use any of those functions you also explicitly set the context of the "this" keyword of the target function to be that of whatever was passed as the first argument.

  7. So what is the use of bind here ? To execute the function as code ? I also see that you cannot pass an Array variable in the bind. can you please clear. its a very nice video. I like it a lot.

  8. hi there, I am new to javascript..
    I tried
    {var y={b:2}; 
    var x={a:10};var z=function(c){ return this.a + c;   //  use this.b + c result is weird.
    };console.log(z.call((y,x),2));}

    its giving me weird results.

Leave a Reply