A Better setTimeout

If you’ve ever used JavaScript’s setTimeout and setInterval methods. you’ve probably found them just a bit … inadequate.

  • Both return an integer rather than an actual handle.
  • If you’re using both setTimeout and setInterval, you have to remember whether the integer value is a timeout or an interval in order to call the appropriate clearXXX method.

Continue reading

Defining Return Objects in Javascript

… or, Prefer this scope to closure scope, Prefer stub scope to this scope

JavaScript is a very flexible language like Perl, and so gives you many ways to carry out the same task. Take something simple like writing a function that returns an object. How many ways can you think of to do that?

If you’ve heard of the Module Pattern, you might think that this is a well-settled question. But the Module Pattern gives you lots of leeway in implementation. In this post I’ll take away most of that wriggle room.

Continue reading

Reflections on NationJS 2013, part 1, the Morning Sessions

My morning began pleasantly with an easy drive from Columbia to Silver Spring. Kudos to the House Republicans who shut down the federal government just so I could have a faster commute to NationJS! I can’t say how much I appreciate having congressman who know how much I hate sitting in traffic and are willing to go to such great lengths to convenience me. As I write this now, it’s been nearly two weeks of the shutdown. I guess I forgot to tell my Tea Party friends that NationJS was only one day.

This very first NationJS was being held at the Silver Spring Civic Center, right next to the Silver Spring Metro Station. I parked right across the street for $1 an hour. Probably not the cheapest spot, but it won’t break the bank.

Breakfast was provided — muffins, bagels, coffee, juice. Quite a few people were there early, which surprised me. There were also plenty of extension cords, but I’m glad I brought my Haskell laptop, so I didn’t have to constantly worry about trying to find an outlet.

The following are my impressions of the four morning sessions I attended. They are in no way meant to be anything near a complete transcript.

New Rules for JavaScript by Kyle Simpson

Kyle started off the keynote with the statement “I’m known for strong opinions” which was a good sign. He introduced some of the projects he was working on such as

Dojo AMD incorporating third party scripts

So, you’ve started using RequireJS or you’ve upgraded to the latest version of Dojo and have converted your web application over to Asynchronous Module Definition (AMD) loading. However, your code still depend on some third party non-AMD scripts. Can and should these scripts be incorporated as AMD dependencies? By “non-AMD” I mean the third party scripts which are not wrapped in a define() or require().

define([ /* ... */], function(){
   //... body of third party script

The most important question to answer is: Can you modify the code?

Continue reading