Thursday, August 14th, 2008

Secrets of the JavaScript Ninja: A sneak peak for Ajaxians

Category: Books, JavaScript

John Resig is working on the Secrets of the JavaScript Ninja book, which I am sure will be a success.

Manning has been kind enough to give us a sneak peak at some of the chapters:

How closures work

This content introduces the closure, an important aspect of JavaScript, and describes its use. It goes into detail on making private data, and dealing with callbacks and timers.

Using (function(){})()

Next up introduces the construct (function(){})() and describes its use in relationship to closures. See how you can create encapsulated temporary scopes.

Instantiation and Prototypes

This section introduces the technique of instantiating a function to give its prototype property functionality.

Class-like Code

And finally we are introduced to the technique of emulating classical-style inheritance in JavaScript.

Posted by Dion Almaer at 6:59 am

4.1 rating from 52 votes


Comments feed TrackBack URI

FireFox 3 opens a new tab and throws a bunch of JS errors when I click on these links, but thats it.

Comment by Jon Hartmann — August 14, 2008

the links to the pdf-files just lead me back to the article. how do i get to the files?

Comment by kioopi — August 14, 2008

Just FYI: These articles haven’t gone through any sort of editorial control at this point so there’s bound to be spelling mistakes, code mistakes, etc. I’m frequently making revisions and posting the current copies up on the Manning site.

Comment by JohnResig — August 14, 2008

Hum, I think that would be a samurai on the cover.

Comment by SamoriGorse — August 14, 2008

I’m having the same issues others are with the PDFs—the links don’t seem to be working at all.

And I agree with “SamoriGorse”… That’s a samurai on the cover, not a ninja. And yes, there IS a big difference.

Comment by PaulArmstrong — August 14, 2008

At least it’s not a pirate. ;-)

Comment by kioopi — August 14, 2008

(in regards to the samurai) While I do feel that it is a very nice cover I completely agree that it is not a ninja (or, at least, not the traditional hollywood ninja). I provided an alternative ninja for the cover, found on the book’s web site: but Manning opted not to use it. Maybe some fuss might sway their minds.

Comment by JohnResig — August 14, 2008

Waiting for the book to released and I know it would be the best book ever on JS. But I wish I can have those pdf’s now :-)

Comment by Teja — August 14, 2008

I’m having the same PDF link issues here; the links just redisplay this page. FF3 Mac.

Comment by jdoree — August 14, 2008

Figured it out – you just have to replace the plus in the url with a “%20” (without quotes). This gets it to work for S3Mac

Comment by fatlotus — August 14, 2008

The links are incorrect, just replace the “+” with a ” “

Comment by Hans Schmucker — August 14, 2008

Just had a quick look at the closures… looks good, no major hickups… however I’m missing one bit that should probably go into the closures chapter: Creating wrapper functions which call a given method in the correct scope… it’s really essential to working with event listeners and solves many problems, especially for former Java developers.

Comment by Hans Schmucker — August 14, 2008

@Hans Schmucker: That’s covered in the full chapter – what’s shown above is just an excerpt of the introduction.

Comment by JohnResig — August 14, 2008

@JohnResig The alternative “ninja” that you provided is MUCH better.

Comment by PaulArmstrong — August 14, 2008

Does anyone from Ajaxian actually read the comments?

Comment by maccman — August 14, 2008

The links work fine in IE6.

Comment by Jordan1 — August 14, 2008

Hahaha… “The links work fine in IE6”. Sorry, that was funny.

Anyway, there is something “wrong” with the links, the href attributes only point to “www.…” instead of “http://www.…” which, in my browser (Safari 3.1.2 on the Mac) just puts the “www.…” as the last part of the path (so it tries to send me to “” for example).

Comment by dreedy — August 14, 2008

Then you can add magic-turning-of-plussign-into-spacesto the list of IE 6 bugs.

Comment by Hans Schmucker — August 14, 2008

Also experiencing the “+” problem in Safari 3.1.2 on Mac.
Exchanging it for a space, which gets converted to “%20”, does the trick!

Comment by dreedy — August 14, 2008

Object.subclass is wreaking havoc on my brain.

Comment by aheckmann — August 14, 2008

I changed the links to not have a space in there and it should work better now for all. Sorry about that!

Comment by Dion Almaer — August 14, 2008

looks hot, and sounds like a must for my book shelf.

Comment by V1 — August 14, 2008

Dying to get this book. When is it coming out?!

Comment by JoeMcCann — August 14, 2008

@all: I’m about halfway done with the book at this point – we’ll have to see how long the next half takes (the next chapters, theoretically, should be easier to write). The final book probably won’t be out until this winter – hopefully in time for Christmas.

Comment by JohnResig — August 14, 2008

With John Resig and Douglas Crockford there are good literature about javascript :)

Comment by RStankov — August 14, 2008

John just had a peek at the prototype chapter. It looks great. I’ve been waiting for your new book since you posted that your doing a new book on your site. Cant wait to get your book on my bookshelf too.

Comment by kenshin — August 14, 2008

Dude, release the book already. I just read the function one, it’s fantastic!

Comment by DanF — August 15, 2008

Great preview, though my boss was upset at the lack of ninja on the cover, as it seems many other people are as well. =p

Comment by Cheston — August 15, 2008

On a pet-peeve/pedantic note …

PEEK, the word is PEEK not PEAK.
Other than that recurring and annoying word misuse, love the site etc.

Comment by Oc73 — August 15, 2008

For me a Ninja has always been a turtle. Since I’m told I’m wrong, I went to Wikipedia, and what did I find in the dress section:

“There is no evidence historical ninja wore all-black suits. In modern times, camouflage based upon dark colors such as dark red and dark blue is known to give better concealment at night. Some cloaks may have been reversible: dark colored on the outside for concealment during the night, and white colored on the inside for concealment in the snow. Some ninja may have worn the same armor or clothing as samurai or Japanese peasants.”

This encourages me to stick with the Samurai guy riding a wave–after all, he ‘s got to be pretty crafty if he’s able to do that.

Comment by manningguy — August 24, 2008

Leave a comment

You must be logged in to post a comment.