-2

It seems bind and call do the same thing. Is there a strength/weakness to each one?

<script type="text/javascript">

    var x = {

        name : "test"

    }
     function a1() {

        a2.bind(x)();            a2.call(x);

    }

    function a2() {

        console.log(this);
    }

    a1();  // output x object.
</script>
runners3431
  • 1,425
  • 1
  • 13
  • 30
  • 2
    `bind` and `call` can be used in different ways to achieve the same effect, for some particular subset of effects. That's not the same as "they do the same thing". If they did the same thing I 'm sure someone would have noticed and removed one of them from the standard by now. – Jon Sep 02 '14 at 20:38

1 Answers1

2

.call executes the function immediately.
.bind returns a new function which can be executed at your convenience. For example it can be used as callback.

Felix Kling
  • 795,719
  • 175
  • 1,089
  • 1,143