Re:Show HN: Chrome Extension to Filter HN Stories by Keyword
by nailer on Tuesday January 24, 2017 @09:02AM
(#13471320)
Rad! You might be able to save a little time/logic by updating the JavaScript from ES3. Instead of:
You can just do:
Likewise...
Can be replaced with:
Chrome supports both the relevant parts of ES6 and ES5 out of the box.
[ Parent
| on HN ]
Re:Show HN: Chrome Extension to Filter HN Stories by Keyword
by alistproducer2 on Tuesday January 24, 2017 @10:07AM
(#13471853)
thanks for the suggestions. I tend to avoid forEach because of the memory overhead (adds function calls where not really necessary). I guess I'm old school, but never got around to using includes. It's been on my radar for a while. I've always tried to write code that is as portable as possible, even though now, with evergreen browsers in the lead, it doesn't really matter as much.
Re:Show HN: Chrome Extension to Filter HN Stories by Keyword
by nailer on Tuesday January 24, 2017 @10:30AM
(#13472086)
Yeah, .forEach() is a new scope. But the better readability is worth the minor performance impact for everything but the most performance-intensive code.
Re:Show HN: Chrome Extension to Filter HN Stories by Keyword
by drenvuk on Wednesday January 25, 2017 @09:24PM
(#13488209)
It's that kind of thinking that gets us really slow software.
Re:Show HN: Chrome Extension to Filter HN Stories by Keyword
by nailer on Thursday January 26, 2017 @07:29AM
(#13490767)
"premature optimization is the root of all evil" - Don Knuth
Also old-style for loops in JS fall victim to the last entry effect since people often use them to set up event handlers and wonder why they don't work.