What are the fundamental things about JavaScript that you wish you’d known when you first started as a developer?
This is a question I have been asked by the amazing Pippa Buchanan from the P2PU school of webcraft. Here is my answer :
I think that JS is a sum of a lot of technologies and that web developers should very early be aware of the differences between them:
1) ECMAScript: That’s the core language JavaScript is based on. That’s “just a programming language”. It defines the JavaScript native types. This include Objects, Arrays and functions
2) The document object inherits form a lot of different interfaces:
- Node which is “just here” for the tree structure (ok, well, a bit more). This interface is common with Elements and contains parentNode, cloneNode…
- Document which contains .createElement, .getElementById. This interface is the one used by the responseXML attribute of XMLHttpRequest. This is common with XML-based documents.
- HTMLDocument. It adds a bunch of HTML-specific things like .body, .links or the .write method (this last one should be avoided, but that’s another story)
- HTML5 redefines the HTMLDocument interface and add for instance .getElementsByClassName()
3) Events
Besides that, the event programming paradigm is not easy to understand. Unlike “C programming” where you have a “main” function and a “return” at the end, JavaScript isn’t continuously executed. There is a bit of execution at the beginning for initialization purposes and after that it’s all user (click/keypress) or network (XMLHttpRequest events) or clock (settimeout) driven which could be all summarized as “events” (even if the clock “events” aren’t DOM events).
The DOM event mechanism is well explained in one picture.
on
2010-11-29
by