Getting Out of Binding Situations in JavaScript

by Christophe Porteneuve

54 Reader Comments

Back to the Article
  1. Hey Varun,

    Well, doh!

    Look at your code:

    doe.fx(‘Mark’)

    This code explicitly calls method fx on object doe.  This is explicit binding, as described at the beginning of the article.  As the fx method was not pre-bound, it uses the explicit binding you give it.

    As I said, methods are not intrinsically attached to a given object.  They use whatever binding is applicable when they’re run.

    ‘hope this makes it clearer for you.

    Copy & paste the code below to embed this comment.
  2. Richard: why, thank you.  ‘most welcome, such “a-ha!” moments are the specific goal of writing such a piece :-)

    Copy & paste the code below to embed this comment.
  3. I apologize for insulting your post. I don’t know how I got on these comments.

    Copy & paste the code below to embed this comment.
  4. thanks for this article…I’ve readed many articles about this (even book’s capitules) and never it had been clear to me…your articles was better than all that books…

    now I’ve a question..why js do it in this way?…I think many times than seemed be a complications in a language in a future this became in advantages…like closures or metaprogramming in ruby…but this binding look very weird to me…this has any advantage?…..

    thank you again and good luck

    Copy & paste the code below to embed this comment.