Skip to main content

Timeline for Loop without 'looping'

Current License: CC BY-SA 3.0

17 events
when toggle format what by license comment
Jul 21, 2014 at 17:03 comment added eithed @Bob that's why I've written new Function + ;)
Jul 21, 2014 at 15:56 comment added Bob @eithedog Similar. .call() calls the function with the new this; .bind() creates a new function with a different this value, which can then be called later - it's a completely independent function. The difference is .bind() actually creates a new function, which addresses immibis' complaint.
Jul 21, 2014 at 15:49 comment added eithed @Bob - good point, though unfortunately it would be the same trick (I guess .bind works the same way as new Function + .call(this)?)
Jul 21, 2014 at 12:33 comment added Bob @immibis Trivial to get around it: tab.f = f.bind({}) (clones the actual function instead of the function reference, so you get an actual new function). You can go the longer way of serialising to JSON and deserialising back to a function, if you want.
Jul 18, 2014 at 18:38 history edited eithed CC BY-SA 3.0
added 17 characters in body
Jul 18, 2014 at 18:37 comment added eithed @immibis - fair point, your comment got me thinking; as functions (and variables) are scoped to the window they're operating in, so the given functions should indeed be different, however the truth doesn't look too good: jsfiddle.net/SV6aa. Oh well, you learn something everyday. Everything here is a loophole - that's the point :D
Jul 18, 2014 at 15:17 comment added jozxyqk I love that browsers, after all this time, are still so vulnerable to stuff like this
Jul 18, 2014 at 7:45 comment added Criticizing Israel not allowed @eithedog the second one is just recursion, AFAIK (unless tab.f = f creates a new function, which would be unexpected, but unsurprising given it's JavaScript). The first one is just trying to use a loophole - it's effectively copyFunction(f)() instead of f()
Jul 17, 2014 at 10:11 comment added eithed @immibis - if I'm not mistaken, in both of the examples new functions are created dynamically - so what that they have the same body as the function that spawned them?
Jul 17, 2014 at 9:59 comment added Criticizing Israel not allowed -1 - this is just recursion.
Jul 15, 2014 at 8:05 comment added Chirag Bhatia - chirag64 Unfortunately, I noticed it because I tried it. :P
Jul 15, 2014 at 8:03 comment added eithed @Chirag64 - it should be similar to previous example, but let's say I didn't want anybody to try it ;)
Jul 15, 2014 at 7:36 comment added Chirag Bhatia - chirag64 I think you're missing an f at the end of your second function. It should be }f() in the end.
Jul 11, 2014 at 11:44 comment added seequ @CailinP Pretty eval for sure.
Jul 9, 2014 at 18:52 comment added CailinP This is pretty evil for sure ;)
Jul 9, 2014 at 17:03 history edited eithed CC BY-SA 3.0
added 360 characters in body
Jul 9, 2014 at 16:52 history answered eithed CC BY-SA 3.0