3 ms·
> It also doesn't qualify as a brain teaser, IMO. That's debatable. It requires a piece of unusual thinking ('return this'), and a bit of magic (knowing about
by fragmede 12y ago
> It also doesn't qualify as a brain teaser, IMO.
That's debatable. It requires a piece of unusual thinking ('return this'), and a bit of magic (knowing about the 'this' magic variable), but once you've seen it, the answer's obvious, and it's pretty easy to replicate everywhere.
- bzalasky 12y agoUnderstanding 'this' is foundational when it comes to understanding JavaScript, IMO. So, I don't think it's that unusual. Out of curiosity, what's another question that demonstrates a solid understanding of JavaScript as a language?
- fragmede 12y agoYeah, but returning 'this' to let you chain things like that? Definitely a trick. Not as obscure as Duff's device, but a trick, nonetheless.