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

For 6), a question, is .bind not just returning a new function, which will .call your provided one with the supplied "this"? That is, I think it's better to reason about it not as an exception to the usual semantics, but as something that can already be done by any coder in the language itself, using the usual semantics.

And thank you for 5), I didn't know it! :)



That's a reasonable way to think about bind().

On a pedantic note, due to complications with the new() operator, you can't actually implement .bind() in JS using only .call() and .apply() and get the prototype of the resulting objects right.


Would you clarify?


My comment was wrong, I was mis-remembering a bug that I'd seen before. You can get everything correct with the prototypes, but you cannot perfectly emulate it.

The only thing you can't do with JS emulation of .bind() is the ability to create a varargs constructor (https://bugs.webkit.org/show_bug.cgi?id=26382#c29). But at the same time, I don't totally grok that example yet. The relevant bit of the spec is http://es5.github.com/#x15.3.4.5.2, which describes the [[Construct]] behavior of .bind().




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

Search: