Stop writing milliseconds and hating JavaScript's setTimeout & setInterval
github.com
github.com
function after(seconds, fn) { return setTimeout(fn, seconds * 1000); }
function every(seconds, fn) { return setInterval(fn, seconds * 1000); }
var MINUTE = 60, HOUR = 3600;
in my program?I do like the naming and argument order better than the standard functions, but the cost-to-benefit ratio of this library seems off by two orders of magnitude, given the ability to get the same benefit in two or three lines of code instead of 200 or 300.
By the way, the argument order and flexibility is what contributes to most of those lines.
...unless you're talking about computer programming instead of physics, in which case one uses counts of milliseconds, microseconds, or nanoseconds. Also remember that integers are valid floating point numbers, so after(100) is ambiguous in the context of computer programming (as pointed out by the prior poster).
Not every single thing needs to be wrapped in a jQuery "helper". Doing that just makes the developer using it more reliant on jQuery and less experienced/knowledgeable about straight JavaScript.
That said, sure, this isn't exactly a huge issue that's plaguing the javascript community. I probably won't use this plugin.
5 * MINUTE
3.5 * HOUR
etc.(My point is: a library may be more appropriate in the JavaScript case, because of the lack of constants.)
So I generally have a non trivial minimum bar for using a library in my code - it has to do more than just a little syntactic sugar.
Programming is about solving problems, and if someone else has already solved a problem in a generalized and reusable way, at the end of the day you haven't created value by insisting on recreating that solution yourself. Please note that I'm referring to getting things done, specifically in industry; I'm not arguing that also understanding the lower levels is a bad thing. For example, I would love to thoroughly understand x86 assembly, and it would probably make me a better programmer (it couldn't hurt), but that doesn't mean I would refuse to use a high level language.
Being "reliant" on jQuery and its plugins isn't a bad thing if you're a web programmer that will always be able to use those tools. You can always go down another level and call someone "reliant." If you use pure JavaScript, then you're "reliant" on the browser's implementation. If you wrote the browser's JavaScript implementation in C++, you're "reliant" on the C++ compiler. Perhaps by the end of the day you're an x86 assembly expert, but now you're "reliant" on the assembler until you memorize the bit strings of all the hundreds of instruction.
Code re-use is great, when it makes sense. Requiring jQuery and a ~250 line script, so you can use "5 minutes" instead of (5 * 60 * 1000) is ridiculous, and any developer who does that would get a bollocking if they reported to me.
underscore.js has a nice alternative for setTimeout() and several functions that probably should be used instead of setInterval() in most cases where setInterval() is used:
On a side note: when is one of these big companies going to release a really advanced "jquery for webkit" that forgets about the browser incompatibilities and focuses on building a virtual operating system in the browser? Google, Apple, Netflix? Anyone?
Feel free to build on top of my code though!