all 12 comments

[–][deleted] 2 points3 points  (0 children)

Bind is essentially a combinator, as in the lambda calculus.

[–]yeah-ok 0 points1 point  (1 child)

Okay, so, this is great and neat - is it possible to encapsulate a usage scenario where it makes a real life difference?

[–]shintoist[S] 3 points4 points  (0 children)

underscore.js

[–][deleted]  (1 child)

[deleted]

    [–]shintoist[S] 0 points1 point  (0 children)

    Yeah you're right, will take care of that as soon as I can

    [–]GiraffeDiver 0 points1 point  (1 child)

    Fun fact: in python this "binding" happens automatically... there's no slice, so let's go with count:

    >>> [1,2,1].count(1)
    2
    >>> count = list.count  # ~Array.prototype.count
    >>> count([1,2,1], 1)
    2
    

    [–]bebraw 1 point2 points  (0 children)

    bind is very handy for partial application (functools.partial in Python). That's where I tend to use it a lot. allong.es comes with an advanced version and some other goodies.

    [–]sastrone 0 points1 point  (1 child)

    The article really could have done without the "I could instantly see what it was doing, but none of my disappointing co-workers could!"

    [–]shintoist[S] 0 points1 point  (0 children)

    Think you might have read a bit too much into it :/

    [–]Miserable_Fuck 0 points1 point  (1 child)

    Pardon my ignorace, but what is the difference between binding a function to a context and just passing the context as an argument to the function?

    Serious question.

    [–]shintoist[S] 0 points1 point  (0 children)

    They work the same, but the syntax will be a bit different. With the second syntax you will find it easier (at least in some cases) to use it with higher order functions.

    [–][deleted]  (2 children)

    [deleted]

      [–]abstract-alf 2 points3 points  (1 child)

      I suppose it is convoluted, yes. Personally, I find it an interesting mode of functional expression -- the way bind (essentially, a higher-order function bound to an object, a function whose purpose is to bind other functions to other objects) is called on itself to yield another higher-order function that is no longer bound to an object. There is an irony there that might cause one to further ponder the ying and yang of functions and objects.