Hacker Newsnew | past | comments | ask | show | jobs | submitlogin

object.bind doesn't look very clean compared to using self.


The nice thing about it is that it allows you to break out of nesting hell while still being prototyped... e.g. window.setTimeout(this.foo.bind(this), baz);

Since .bind is essentially currying, you could imaginably do window.setTimeout(this.foo.bind(this, bar), baz) as well, if foo is dependent on bar (timing out a request `bar' or something like that).


And in JS is really easy to create an abstraction for this issue:

    function wait(o){
      return setTimeout(function(){ o.action.call(o.this) },o.delay*1000)
    }    
To use it like this:

    wait({
       action : function(){ console.log(this) },
       delay : 1,       
       this : this
    });


If you're writing abstractions to avoid bad language features, maybe you shouldn't be using bad language features in the first place.




Guidelines | FAQ | Lists | API | Security | Legal | Apply to YC | Contact

Search: