JavaScript, HTML5 and CSS3 (book/resources)

Status
Not open for further replies.
I'd love to get a much greater grasp on JavaScript. I understand the DOM concepts and most of the basics of the original prototype concept of building over OOP.

Now that more apps are being developed via XHTML/CSS2.x and HTML5/CSS3, is there going to be any revolution on the rise of JavaScript itself? (More question of theory than fact) Just to ask, is the prototypical nature of JavaScript going to stick around for a lot longer?

I'm (and I'm sure many others am) looking for some great books on the subjects of the most modern best practices of JavaScript and CSS3. I want to step a bit away from jQuery more and more, not because I find it irresponsible to use, but because frameworks only do "so much".

Are there any really must-have books that are on the current edge of best practices with JavaScript?

On CSS3 anyone is well-to-do with just a reference so I'm fine with that but if there's any actually interesting books (like back in the original evolution of css, zengarden and such) I'd like to read those as well. Not really just a reference but more of a tricks and techniques as well as best practices type of book.

Thanks for any tips
 

Mile Zero

Ars Praetorian
578
Subscriptor++
You should own Crockford's book on JavaScript. You shouldn't agree with everything in it, but it's a good introduction to the way modern JavaScript is written in order to deal with the language's dire scope issues.

I suspect that prototypes will not go anywhere anytime soon, so it'll be worth learning about how they work (and then deciding the degree to which you actually want to fuck with them). Certainly JavaScript itself will probably not change noticeably for a while, even though the next version is under development, simply because browsers have been slow to implement the new features of the language. And while HTML/CSS can degrade, that's a much more difficult process when it comes to JS language features.

One resource that I really, really liked was Paul Irish's screencast on 10 Things I Learned From The jQuery Source. Like it or not, jQuery is a big project being built by some fairly smart people, and you can learn a lot from the way that they've built and are managing its codebase.

I recently bought the O'Reilly High Performance JavaScript book. It's not bad. I don't know if I'd recommend it, though.
 
Thanks for the tips. I have actually read that blog, bookmarked a while back. I do agree it's very good! I also started watching all crocks videos on javascript (those mega long over verbose videos). He's definitely a good source and he's a huge fan of it. I'm not sure I really agree with him that prototype is generally a good idea over converting to OOP but that was a bit of a question here. If in the future prototype would be abandoned.

If anyone has any more gems please share away!

JavaScript is definitely my main concern. I'd like to keep that very tight.
 

Mile Zero

Ars Praetorian
578
Subscriptor++
There are some crazy tricks in the jQuery source, too. I noticed today that instead of populating arrays of string constants directly, they're creating them from a space-delimited string and then splitting it. If you have enough items, that saves characters because you don't have to repeatedly include the quotation marks:

Code:
props: "altKey attrChange attrName ... which".split(" ")

instead of

Code:
props: ["altKey", "attrChange", "attrName" ... "which"]

I'm split (pardon the pun) on whether I should admire the ingenuity in saving a few bytes, or whether I should be kind of horrified that they feel like they have to.

I'd love it if prototypes went away. I personally hate using prototypal inheritance the way it's set up in JavaScript: I hate the weird way that the named constructor takes precedence, I hate having to define the class in two separate places (the constructor and then the constructor's prototype), and I hate the unpredictable scope on the new keyword. Coming from AS3, the whole mess (and the related lack of namespacing) feels like an incredible step backwards. On the other hand, it spawned a kind of miniature renaissance in functional coding, so I guess constraints have their silver linings.

Anyway, last time I did a medium-sized JS project, I ended up implementing an inheritance scheme similar to John Resig's Simple JavaScript Inheritance. I also added a mix-in system for faking interfaces, and that got rid of a lot of pain points.

One of the interesting points for me in the High Performance JS book was that it detailed how scope chains become increasingly expensive, particularly in older browsers. So all the work that people like Crockford did on using closures for variable hiding and for functional programming had its upside in that it allowed the language to (partially) make up for its horrible, horrible scoping flaws. But it also has a pretty serious cost in speed and memory--a functional each() loop in jQuery is anywhere from 5x to 60x slower than a straightforward loop, for example, depending on the browser. And if you nest your closures, that can get worse. So I think for me, the key has been learning to find a balance between elegance and performance.

A big offender for me is event listeners. In ActionScript, you get that nice, defined Event class (or subclass) with a target property that you can reference in your listener function. Whereas in JavaScript, the common practice is for listeners to be bound to "this." Then if your listener does anything using an inline or anonymous callback (AJAX or functional iteration comes to mind), now you've got to keep track of which "this" you're actually referencing at any given time. I had a ton of bugs thanks to that. Those kinds of things aren't unforeseeable or difficult to work around, but they're a hassle that the language does nothing to discourage or make intuitive.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
In a Crockford like step, I have basically banished "this" from my JavaScript code. This helps to avoid issues with event listeners, inheritance, etc.

I try to sketch out all code and processes using straight up inheritance without any prototypes and without using this.

After its done, its easy to identify the 2 or 3 places where performance or memory usage is significantly reduced by using prototypes or this and add it back in.

The result is code that performs well, has fewer bugs and is written more quickly.
 

Blacken00100

Ars Legatus Legionis
10,130
Subscriptor
Short list (if asked, can amplify later):

HTML5, by Bruce Lawson and Remy Sharp
JavaScript: The Good Parts, by Douglas Crockford
Bulletproof Web Design, by Dan Cederholm
Handcrafted CSS, by Dan Cederholm and Ethan Marcotte
Responsive Web Design, by Ethan Marcotte

The last three books are a very opinionated set of books about How To Do Web Design Correctly, but they include a lot of really good information on defensive [X]HTML and CSS. Responsive Web Design is probably my favorite tech book, ever.
 

tinyMan

Ars Tribunus Angusticlavius
6,149
Subscriptor++
Also, since it hasn't been thrown in yet, I will recommend really taking a look at the HTML5 Boilerplate and especially the documentation and videos that cover WHY the boilerplate code and processes are laid out like they are.

I used HTML5 Boilerplate as the start of our own internal website framework template and it has been very good to me.
 
Excellent insights and recommendations, thanks a bunch! I will definitely go from 2 angles and meet in the middle. I'll grab the boilerplate and Crockfords book (as I've heard that recommended uncountable times, which is why I watched the videos). Then meet in the middle with something more modern.

I need more roots before sprouts with JavaScript but it does exhibit all the pains I hated about actionscript 2. Albeit object based (loosely), scope always came from the caller and you always had to bend over backwards to run code from whatever scope your event left you in. So I understand completely what you mean when AS3 cleaned all of that BS up.
 
Status
Not open for further replies.