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

I agree. The fact that you have to write library code defensively to still work depending on how your method's call, or that you have to use an awkward bind to preserve the `this` context of a method is so annoying and error-prone to me.


Even when you remember to perform the awkward bind / Function.prototype.call / Function.prototype.apply / var self = this; you still may already be inside of another context where this is not correctly defined. So then your code LOOKS even more like it will work thanks to the cargo cult magic ceremonies you've performed perfectly, but in the wrong place. It's like going into the bathroom like you're supposed to, but then taking a shit on the floor right next to the toilet, then flushing.


I don't think that's how bind works. Can you give a code example that shows unintuitive behavior? What I'm hearing from you is something like:

    function foo() {
        var bar = function() {
            console.log(this);
        };
        return bar.bind(42);
    }

    foo().call(1337); // prints 42
...which behaves as expected, so I'm not sure what you're getting at?




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

Search: