Created
June 30, 2013 23:25
-
-
Save elliot42/5897434 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
JS Include Structures | |
Multiple add_javascripts | |
- Clear code | |
- Bad for perf (multiple HTTP requests) | |
ONe big manifest | |
- | |
Our convention: | |
- Things taht are generally going to be served to most people anyway, | |
or more than one 'section' / ('global') goes in the application | |
manifest. | |
Section manifests | |
- Collect all code for a section into a section manifest. | |
- We're doing this. | |
RequireJS and other script loaders | |
- (We're not using this.) | |
- Declare dependencies in JS | |
- (Various ones work either server or client side) | |
- Adds boilerplate to set up | |
- These have many magical tools to optimize number of requests and | |
things. | |
================================================== | |
Prototypal stuff (Causes.classify...) | |
- When you `new Thingy` it auto calls init. | |
- This lives in prototypal.js | |
- Not 100% clear when to use this vs. other structure | |
- Do this when you want multiple instantiations of an object. | |
- There's already singleton support in here. | |
- Though possibly questionable whether or not we should use this vs. | |
just a standard single JS object. | |
Backbone may change some of this stuff. | |
Next FEWG mtg. is next Tuesday. | |
================================================== | |
for loops: | |
Newer JS has foreach | |
We DON'T have a polyfill for foreach?, and have monkey patched array object | |
for browsers that don't have it. | |
for (ix in []) { | |
// ix = 0 | |
arr[ix] | |
} | |
That thing above should also be avoided. | |
Possible options moving forward with underscore.js | |
When writing d3 stuff, use d3 versions of iteration, map, etc. | |
presume to keep d3 separte HTTP request unless charts are really on | |
all pages | |
$('.chart').each(function()) { | |
}); | |
var charts = $('.chart'), | |
chart; | |
for (var ix = 0, chart_size = charts.size; | |
ix < charts_size; | |
++ix) { | |
charts[ix] | |
} | |
In simple case, go with readable. | |
If there's a bunch o' elements, do the c-style loop. | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment