I’ve been kept watching the Fronteers 08 conference videos recently and I found Christian Heilmann’s “maintainable JavaScript” very useful.
One of the tips that I’ve learnt is that “always keep styling code in CSS”. It sounds very normal and everybody should be doing this already, but I think it’s not the case in real world.
For example, to hide an element using JavaScript, we will usually do this:
elem.style.display =’none’;
However, you may want to use: style.visibility = ‘hidden’ to hide the element for some reasons later. So what Christian Heilmann suggests is to truly separates the logic in JavaScript and styling in CSS:
For example, in JavaScript:
elem.className = 'hidden';
And then in CSS:
.hidden {
/* you can change this to visiblity: hidden or a large negative margin to hide the elem */
display: none;
}
You can find the full presentation videos here:
Part 1
Presentation: Christian Heilmann: Maintainable JavaScript, part 1 from Bachelor-ict.nl on Vimeo.
Part 2
Presentation: Christian Heilmann: Maintainable JavaScript, part 2 from Bachelor-ict.nl on Vimeo.
no comments
RSS / trackback