The reduce ({...spread}) anti-pattern

I thought this was a really interesting examination of the performance penalties of using ({...spread}) in JavaScript. Link: The reduce ({…spread}) anti-pattern

December 21, 2021 · Morgan Roderick

JSDoc typings: all the benefits of TypeScript, with none of the drawbacks

An in depth exploration of how far you can get with using JSDoc (and the TypeScript compiler) without resorting to writing TypeScript or having a build step in your project. Link: JSDoc typings: all the benefits of TypeScript, with none of the drawbacks

July 20, 2021 · Morgan Roderick

The (extremely) loud minority

It’s understandable to think that JavaScript frameworks and their communities are eating the web because places like Twitter are awash with very loud voices from said communities. Always remember that although a subset of the JavaScript community can be very loud, they represent a paltry portion of the web as a whole. This means that when they say something like “CSS sucks” — what they mean is “CSS sucks for a small subset of less than 1 percent of the web”. ...

November 12, 2020 · Morgan Roderick

Avoid double exclamations in JavaScript

There is a common misuse of JavaScript’s type coercion that I see in code reviews. It’s the terse use of two exclamation marks to convert a truthy value to a Boolean value. Here’s an example: const someValue = "I like apple pie"; const userLikesPie = !!someValue; // userLikesPie is now `true` I think this is a misuse for two reasons: it obscures intent for people that are not fully aware of JavaScript coercion it is easy to introduce a mistake that can be difficult to detect As for the first point, you could argue that it is the reader’s responsibility to educate themself in order to fully understand the code. However, there isn’t much value in winning that argument if the reader misunderstands the code and introduces new bugs. ...

September 10, 2018 · Morgan Roderick

jQuery Data Link considered harmful

“Considered harmful” has always been good link bait. I am not trying to start a flamewar, but merely express my concerns over the recent decisions of the jQuery team to actively endorse plugins that deserves no special treatment from any other plugins out there. If you have different opinions, please do respond in the comments or write a blog post expressing them. Extending globals with interesting side effects When Prototype was first released, everyone was really excited and could suddenly do a lot more with JavaScript across browsers, that would have been considered almost a black art before (to some it still is). ...

November 3, 2010 · Morgan Roderick

Introducing PubSubJS, a library for doing publish/subscribe in JavaScript

For quite a while, I have been working on a large web application for a client. For publish/subscribe style messaging in the web frontend, we use jQuery custom events triggered on the body element. This is quite a neat trick to ensure loose coupling of modules, since you’re really just tracking what the user does, and not what module happened to generate the message. This approach has been introduced to my team by me, and I have been very eager to help my team mates understand how to use it. ...

October 12, 2010 · Morgan Roderick

Introducing FailFast, a JavaScript library for failure

Tomorrow I will be attending dConstruct 2010, which I am very excited about. I flew in a day early, so I could get some time to enjoy Brighton. One of the first stops has been The Skiff, “a nice little place to work in the middle of Brighton”. The Skiff is indeed a very nice place: very few interruptions and very friendly people. While sitting at my visitors desk, I’ve managed to finally finish a little JavaScript library, that has been a very long time in the making: FailFast. All it took was tidying up the documentation and writing the last few missing unit tests. ...

September 2, 2010 · Morgan Roderick

IE8 Getting EcmaScript 262 rev. 5 Compliant Native JSON

Earlier this week, Microsoft posted an article with details on udpates to the native JSON implementation in IE8. Because of the new ECMAScript specification changes, some customers have reported issues. These issues are caused by deviations between the native JSON feature in Internet Explorer 8 and the final specification. An update is now available to address these customer issues and improve JSON interoperability of Internet Explorer 8. This update enables JSON interoperability of Internet Explorer 8 to keep in conformance with the new “ECMAScript, fifth edition” standard specification. ...

February 26, 2010 · Morgan Roderick

Combining JavaScript Files - Juicer vs Sprockets

Currently working on a project that has well defined use of “namespaces” and structured use folders for its JavaScript files. I wanted to investigate the options for combining and minifying JavaScript files. I need a tool that: can be run from command line (my team uses many different editors and IDEs) will work on both Windows and Unix based platforms does not require huge, obscure configuration files can merge sources recursively has an acceptable software license (MIT / Apache / BSD) is thorougly tested is extensible can work with any JavaScript framework I settled for trying out Juicer and Sprockets, since both tools met the requirements and were the only high-quality tools on my radar. ...

October 4, 2009 · Morgan Roderick

TextMate snippet for creating Low Pro Behaviors

Behaviours To encapsulate complex javascript behaviour on websites, I have been using Dan Webb’s Low Pro library for several years. Low Pro allows you to create self-contained Behavior classes, which avoids polluting the global namespace with variables and makes for very easy re-use of code. I’ve previously given a little introduction to Low Pro for Prototype at a local Meetup event, where I show an example of creating your own behaviours. Textmate snippet Today, I finally got around to creating a TextMate snippet for creating new Behaviors. ...

August 16, 2009 · Morgan Roderick