News for hackers. Stuff that matters.
Re:WTFJS? by Tichy on Friday February 12, 2010 @05:35PM (#1122004)
"(x=[].reverse)() === window // true"

Didn't understand this one at first, but I guess it is easy: first x becomes the reverse function of arrays, then it is called with this === window. So it amounts to window.reverse(). Just looked it up, and reverse() works in place, so window.reverse() === window - although it is potentially different from before.

Re:WTFJS? by andreyf on Friday February 12, 2010 @09:07PM (#1122382)
No, it amonts to Array.prototype.reverse.call(window) - window doesn't have a reverse method AFAIK, so window.reverse() will raise a TypeError (since you can't call something "undefined").
Re:WTFJS? by Tichy on Saturday February 13, 2010 @11:09AM (#1123126)
are you sure? i thought in js functions are not really tied to "their" object, instead they receive an implicit this argument. wouldn't x belong to window here? that is, window doesn't have reverse, but now it has x
Re:WTFJS? by est on Friday February 12, 2010 @09:41PM (#1122427)
I smell a potential DOM injection XSS here.
Re:WTFJS? by jauco on Saturday February 13, 2010 @05:17AM (#1122858)
How? The only reaon this works is that 'this' in a function that is not called on an object will default to the global object (window for browser js).

So just saying 'this' in an arbitrary function has the same effect.

Re:WTFJS? by gcb on Saturday February 13, 2010 @08:48PM (#1123948)
but `this` is filtered by most js clean up libs.