Michael Grischenko

Read this first

Organize jQuery code without a framework

When I look for ways to organize my jQuery code on the internet, what I find are usually advices on what framework I should use. Using a framework is a good idea because good frameworks enforce good design practices. But the core of any framework is just a set of rules, so if you want to keep things really simple, you can adopt some of those rules to write good JavaScript without any additional libraries. This is particularly useful when you just need to add some dynamic functionality to a html page and using something like Backbone or Angular seems an overkill. I use this technique for small projects or when prototyping interfaces.

Here are two rules I adopted from frameworks for my jQuery code:

  • Write isolated pieces of code that only control a specific element on the page. I will call these pieces controllers for convenience.
  • Define behavior of a controller only by attaching event...

Continue reading →

Using private methods in CoffeeScript

I am a big fan of CoffeeScript. Its simplicity and expressiveness made me more productive and helped me better understand JavaScript. Its syntax emphasizes lambdas and promotes best JavaScript practices, hiding away unneeded hackery. It also addresses many common issues with vanilla JavaScript, like making extending objects easier or providing super method.

But CoffeeScript stays true to the nature of JavaScript, combining brilliant solutions with highly questionable ones. What I particularly dislike about CoffeeScript is how it obscures JavaScript’s native scoping mechanism and makes using private object properties inconvenient and counter-intuitive. As a result, many developers who use CoffeeScript don’t even know they can use private properties and methods. Private methods are virtually extinct in the world of CoffeeScript, and this is not a good practice. Search by word ‘private’ on...

Continue reading →