Take your JavaScript Up a Notch

Blog Post created by odoe on Jul 8, 2015


I'm going to assume you are currently building apps with the ArcGIS API for JavaScript or you plan to. Maybe you've been doing stuff in Flex or Silverlight and you've put off the switch until now.  wanted to address a few things I've seen pop in the forums that aren't necessarily related to the ArcGIS APIs, but maybe more in how JavaScript itself works. I also wanted to give your some resources to up your JavaScript game.


Learn the basics

Closures. I can't emphasize this enough. Learn scope, learn closures and variable declarations. So many issues that pop up on these forums have to do with errors in scope, this will be a lifesaver.


I've covered promises before, but I'm going to emphasize them again. Learn promises. Here's a cool blog post on promises. Learn how to chain your promises. Promises are used throughout the ArcGIS JS API. You may not need to use dojo/promise/all, or have nested callbacks, you may just need to chain your promises. Heck, don't even use callbacks, just use then and otherwise.


Arrays. I'm going to go ahead and say that a better understanding of arrays and their methods will make your JavaScript life so much easier. You can do so much with arrays, I can't possibly mention them all. You can filter them, you can map them, you can reduce them. You can treat them as immutables by using concat and slice. If you can master arrays, you'll find that your JavaScript prowess will grow exponentially.


The last basic thing I want to mention here is Object.prototype. Don't forget that JavaScript is a prototype language. You may think you are working with classes and classical inheritance, but part of the beauty of JavaScript is that you can treat it like that if you want, but it's simply not true. Here is good answer to this question on stackoverflow. If you ever want to up your game and play with a purely prototype language, check out io.


Resources to up your game

So if you are new to JavaScript or maybe looking for a refresher, I think Eloquent JavaScript is a good starting point. It covers a lot of ground, including canvas and Node.


Here is a great document from Esri training on resources for the ArcGIS API for JavaScript.


You Don't Know JavaScript.

This is a free book on github, but you can purchase print copies. I've see one of Kyle Simpsons online training courses for JavaScript. Even if you think you know JavaScript, he'll show you something you don't know. This is very in depth stuff and highly recommended.



The Mozilla Developer Network. This is like having the JavaScript specs laid out for you in a nice informative fashion. This is a must-have reference when doing JavaScript development, all the samples are easy to understand and it's easy to know which features are experimental.



The spec is final, it's done, it's coming. I expect we'll see more features roll out in browsers over the next couple of years. Things like import may take a while, but the future is now, stop fooling around.


Functional Programming.

Ok, this one is like a teachers pet. Do I think everyone should be doing functional JavaScript? Maybe("Yes"). I'm kidding. But I do think you could learn a lot about JavaScript development by learning how to use it in some functional programming manner. You don't need to know Monads, but you already know Functors. (Arrays are Functors, which are containers that can be mapped with functions to get their values). I'm not a pro, but an avid admirer and user.


Reactive Programming

This kind of ties right into Functional Programming. Reactive Programming is dealing with streams or asynchronous data over time. The link provided is a great resource. There are libraries like RxJS and Bacon to help you out here.


I think that's enough to get you going for now. It's not totally related to the ArcGIS API for JavaScript, but trust me, master the basics, learn a little of the extras and you will definitely be rocking some higher level JavaScript.


For more geodev tips and tricks, check out my blog.