Created
April 8, 2010 14:24
-
-
Save remy/360113 to your computer and use it in GitHub Desktop.
setInterval run once, then keep running
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
setInterval((function () { | |
console.log(new Date()); // run some arbitrary code | |
return arguments.callee; // here be the magic | |
})(), 1000); | |
// ^---- and that runs the function, and the return val is assign to the interval |
Accessing the arguments object is very slow.
http://www.jspatterns.com/arguments-considered-harmful/
http://webreflection.blogspot.com/2010/02/arguments-callee-call-and-apply.html
@getify, i'm aware of the NFE scope leaking bugs in IE, but not any memory leaks..
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
How does a named function help with performance?
Also, I prefer the arguments approach better, since it's very useful when creating, say, a library. If I pass the arguments object to the library, the lib has got context of both caller and callee with a simple API. In ES5, the API would get complicated. This has been my biggest gripe with ES5.