Not only was Stoyan Stefanov nice enough to submit an excerpt of his book, JavaScript Patterns, to Nettuts+, but we also have ten digital copies available to give away to our community! Personally, I’m roughly 75% finished with the book, and it’s fantastic. Similar to his previous book, “Object-Oriented JavaScript,” Stoyan has an uncanny ability to make high level techniques and concepts as easy as possible to understand. Even if you don’t win a copy, “JavaScript Patterns” receives my highest recommendation.
Update: Winners Announced!
Congratulations to the following Tweeters for winning a copy of JavaScript Patterns!
Dine: Always specify the second param (radix) to parseInt(string, radix) #jsEdu
javascr1pt: Put your JavaScript code right before the
tag for optimal loading. As @souders says, Render first. JS second. #JSedu #JavaScript
ripter001: Instead of if( i % 2 ) to detect even/odd, use if( i & 1 ) It’s faster because of the bit operator. #jsEdu
josephs: ensure your page is functional before applying JavaScript. JavaScript should be then used to enhance the page – progress. enhancemnt #jsEdu
Fcalderan: before writing a single line of javascript, seriously think if you can reach the same result in newest browser with only CSS =) — #jsEdu
zoraslapen: RT @acazsouza: Stop using “return false” to all and learn about “event.preventDefault” and “event.stopPropagation”: http://bit.ly/aGJsxe (expand) #jsEdu
tamtamchik: Good way to minimize the use of global variables is to create a single global variable for your application: var app = {}; #jsEdu
garbrand: Quick js tip: set up your editor to validate your JS on each save with JSlint. Saves me multiple times per day. #jsEdu
jwmcpeak: Objects can be used as hash tables. obj["myMethod"](); is the same as obj.myMethod(). #jsEdu
ColmBritton: Comment, comment, comment. Your code is only a view source away from anyone so educate and help them understand your mind. #jsEdu
How to Win a Copy
Leaving a comment to enter is old-fashioned; let’s help educate the TwitterVerse. In 140 characters or less, tweet a JavaScript best practice, and then hash, “#jsEdu,” like so:
On October 14th (US EST), I’ll choose ten helpful tweets that contain the #jsEdu hash, and update this posting to announce the winners!
What’s the best approach for developing an application with JavaScript? This book helps you answer that question with numerous JavaScript coding patterns and best practices. If you’re an experienced developer looking to solve problems related to objects, functions, inheritance, and other language-specific categories, the abstractions and code templates in this guide are ideal — whether you’re writing a client-side, server-side, or desktop application with JavaScript.
Written by JavaScript expert Stoyan Stefanov — Senior Yahoo! Technical and architect of YSlow 2.0, the web page performance optimization tool — JavaScript Patterns includes practical advice for implementing each pattern discussed, along with several hands-on examples. You’ll also learn about anti-patterns: common programming approaches that cause more problems than they solve.
Explore useful habits for writing high-quality JavaScript code, such as avoiding globals, using single var declarations, and more
Learn why literal notation patterns are simpler alternatives to constructor functions
Discover different ways to define a function in JavaScript
Create objects that go beyond the basic patterns of using object literals and constructor functions
Learn the options available for code reuse and inheritance in JavaScript
Study sample JavaScript approaches to common design patterns such as Singleton, Factory, Decorator, and more
Examine patterns that apply specifically to the client-side browser environment
About the Author
Stoyan Stefanov is a Yahoo! web developer and an author, contributor, and tech reviewer of various O’Reilly books. He speaks regularly about web development topics at conferences and on his blog at www.phpied.com. Stoyan is the creator of the smush.it image optimization tool, YUI contributor and architect of Yahoo’s performance optimization tool YSlow 2.0.
Note: Want to add some source code? Type <pre><code> before it and </code></pre> after it. Find out more
I was just browsing amazon.co.uk looking for JavaScript books when I saw the tweet. Just tweeted my best practice tip…
http://www.mrbrewski.co.uk Daniel
Sounds like a good read XD
Varun
Always use Try…Catch Statement It may be useful for all webdevelopers to check if there is an error or not. for example: try { //Run some code here } catch(exception e) { //Handle errors here } .#jsEdu
Isnt this a little flawed? Surely the readers whod benefit most from this book are the ones who arent in a position to give succinct JS tips over Twitter. Why reward the readers who have little to learn from a book like this?
http://www.jeffrey-way.com Jeffrey Way
Author
The book is actually for Intermediate to advanced programmers.
@netzzwerg and my last one: promote #promotejs for better #jsEdu
http://www.russelluresti.com RussellUresti
My JavaScript best practice tip? When all else fails, ask someone better at JavaScript than you. Or am I the only person who bugs co-workers with development questions?
http://www.flickr.com/photos/ladron_de_visiones/ Francesco
Use a js pattern:
function myObject = function(){
//private space
var secondsPerMinute = 60;
function getSecondsFromMinutes(minutes){ return minutes * secondsPerMinute; }
// the returned object is the public space return { getSecondsFromMinutes: getSecondsFromMinutes }
}
myObject.getSecondsFromMinutes(3) //return 180!
Francesco
Oppps, I’ve forgot the
function(){
….
}();
http://twitter.com/scottpalmer Scott Palmer
Any thoughts on when the winners will be announced?
http://www.jamonn.com/ Marco
And the list of winners?
Julius
Perhaps there are no comments that are worth to be rewarded with a book :( …?
Askar
Yeah, where is the list of winners? Cheers!
http://www.jeffrey-way.com Jeffrey Way
Author
At the top.
http://www.jaaulde.com/ JAAulde
I don’t mean to be a sore loser, but I don’t understand how a comment I posted days before someone else can land them a win…?
http://www.jeffrey-way.com Jeffrey Way
Author
Because it’s partially random.
http://www.jaaulde.com JAAulde
Ah, ok then. Makes more sense–wasn’t sure how you’d go through all those posts to determine the 10 best.