← Back to Upcase

Sandi Metz' Four Rules in Javascript?


(Dave West) #1

Just wondering if you guys follow the four rules in your javascript as well. If so, do you have any tricks to share? For example, Matt regularly extracts variable assignment in the Rails videos to their own methods which reduces the line count of the method in question by 1. Any tricks like this in your JS?


(Ben Orenstein) #2

I’m not sure if any teams have explicitly done this for javascript, but I think it would make perfect sense to shoot for the same goals in js as ruby: small classes and short methods.

Even without the “rules” in place, our teams tend to write code that exhibits the same properties as those explicitly following them.


(Justin Gordon) #3

@benorenstein There’s a very popular JS library that I use, called FancyBox.

Here’s the source below. What do you think?

Is writing Javascript just a totally different beast than Ruby (and even CoffeeScript) given the reliance on closures? It seems that this style of JS is the norm. Does anybody else share my frustration with trying to grok this when one is used to small classes and small methods in Ruby?

https://github.com/fancyapps/fancyBox/blob/master/source/jquery.fancybox.js