Here’s some complicated things I learned from him:
- Reassigning the CSS class of a DOM element at runtime is totally OK. In jQuery, it’s like doing
foo.attr("class", "someStyle"). It’s a handy way to make the document suddenly look different, but it made me nervous.
- Editing the CSS style of a DOM element is also OK. In jQuery, it’s doing
foo.css("font-weight", "bold"). Presumably it’s using
element.style.setProperty()to do the manipulation.
Also some simple things:
Array.join()just like Python. Handy to avoid lots of String concatenation.
- Not clear that testing
if (foo === 3)is worth typing the extra =. There’s circumstances where it saves you, but in practice may not be a big deal.
Array.push()can take multiple arguments, to avoid repeated calls
return "" + xis an easy way to ensure the return type is always a string
I learned a lot. Code reviews are a great way to teach and learn, it’d be nice to have an online community that offered them along the lines of StackOverflow or github. Both for basic education, but also helping clean up important open source libraries. Key tech piece: a really good browser based code annotation tool.
Now as a favour in kind I’m going to try porting my code from using jQuery to using his D3 library. D3 is more of a visualization library than a jQuery replacement, but it happens to have the selectors and Ajax support I need.