I have always used javascript as the glue for my browser widgets and pages. I had done some early prototyping (Javascript's OO technique). This series of videos from Douglas Crockford (Javascript Architect for Yahoo!) really opened my eyes to some of the more subtle techniques for doing OO in javascript. There are four parts. Part one delivers your basic language overview, datatypes, operators, reserved words etc. Part two really dives into Javascript OO.
Here are the links
Part 1 History / Javascript language overview
Part 2 OO methods and Arrays overview
Part 3 Functions
Part 4 Nuances and gottchas of the Javascript language
As he states in Part 2 most people think of OO in the classical c++ or Java sense. And when writing OO I tried to make Javascript fit that. I would write functions and conceptualize them as classes. But Javascript is different. Javascript objects can be extended much easier than traditional objects. For example, just use the .notation and make up the new member and set it equal to something, like so
myObj.newMember = newValue;
Kapow! I just extended my original object.
A language aspect that is utilized incorrectly is scope. Scope is very different and limited in Javascript. There are two kind local scope and global scope. Depending on how and where you declare your variable will determine if it is global or local. If you do not understand this scope you may get cross talk between functions that use the same variable names.
He also has an advanced Javascript video series available.
Thursday, March 5, 2009
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment