How true hackers write JavaScript
61–70 of 342 posts
Re: How true hackers write JavaScript
#62In most places this code would never pass a code review and would be considered plain unacceptable. I guess I'd prefer some place where this code style is the norm.
Go into academia. You'll receive no code review, and you'll deal with pretty bad code, but you'll be free to write however you want as long as it works and can be published.
Re: How true hackers write JavaScript
#63It only exists because DOM APIs are crap, and jQuery is too big. So it ends up reimplementing parts of jQuery needed to run.
For the record, jQuery 3.3.1 (production, normal) is at 30kb [1]; if you don't want effects (production, slim), you can get it for less than 24kb [2]. For the value it provides, that does not sound "too big" to me. [1]: https://code.jquery.com/jquery-3.3.1.min.js [2]: https://code.jquery.com/jquery-3.3.1.slim.min.js
Re: How true hackers write JavaScript
#64Re: How true hackers write JavaScript
#65I feel the naming is too short, things are just a little too specifically compact and slightly cryptic ... almost like the author is trying to say something ...
I've never said this before about code ... but I think that code is 'smug'!
Like odd facial hair, or one of those valley-specific t-shirts ... the code trying to project how cool it thinks it is!
That code is 'humble-bragging' ...
Re: How true hackers write JavaScript
#66function aeach (fn, a) { return Array.prototype.forEach.call(a, fn) } Does this win anything over using forEach directly?
A lot of things like this will work on both arrays (thta have a .forEach method) and things that behave enough like arrays such that Array.prototype.forEach works for them. The downside of this approach (if you subscribe to the ideology of OO) is that if you make something completely unlike an array internally, like a linked list, you can’t use this function on it. Whereas, if you wrote a .forEach method for it, you…
Re: How true hackers write JavaScript
#67That might be one of the most readable pieces of code that I've ever read.
Re: How true hackers write JavaScript
#68Re: How true hackers write JavaScript
#69function aeach (fn, a) { return Array.prototype.forEach.call(a, fn) } Does this win anything over using forEach directly?
If you're targeting modern browsers this is no longer an issue, as they all support NodeList.forEach(). It's worth noting that many DOM APIs return live collections, so depending on what you're doing you might want to clone it first. Luckily now with ES2015 you can use Array.from(list) or just [...list].
Re: How true hackers write JavaScript
#70 function hidestory (ev, el, id) {
for (var i=0; i
That 3 there is the problem with “simple” JS. It’s tightly coupled to the HTML but they live in completely different places.On a side note this 3 should be at least assigned to a variable with a meaningful name.