JSLent                          give it up for JavaScriptTuesday, March 22, 2011
Whither JS?                          • In the browsers (obviously)                          • On the server               ...
eschew evalTuesday, March 22, 2011
how prototypicalTuesday, March 22, 2011
function Person(){}                   Person.prototype.getName = function(){                          return this.name;   ...
getting it right                             buy the bookTuesday, March 22, 2011
Meet Douglas Crockford                          • author of JavaScript: the Good Parts                            • minifie...
He begat JSLint                          • cleans up your JS                          • will hurt your feelingsTuesday, Ma...
(function() {               four = eval(2+2);               var eight = multiply(four, 2);               function multiply...
Problem at line 2 character 8: eval is evil.               (function() {                                                  ...
see?Tuesday, March 22, 2011
JSLint: finds...stuff                          • Undefined Vars & Functions                          • Globals/Members lists ...
more stuff                          • singe var at the top                          • no more with                         ...
Awful Parts                          • Global Variables                          • Scope (confusing/misleading variable sc...
Reserved Words                          •   boolean      •   final         •   short                          •   break    ...
Resources                          • jslint.com                          • jshint.com                          • ejohn.org...
Upcoming SlideShare
Loading in …5
×

JSLent: give it up for JavaScript

1,286 views

Published on

Simple ways to improve your JavaScript code.

Published in: Self Improvement
0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
1,286
On SlideShare
0
From Embeds
0
Number of Embeds
202
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

JSLent: give it up for JavaScript

  1. 1. JSLent give it up for JavaScriptTuesday, March 22, 2011
  2. 2. Whither JS? • In the browsers (obviously) • On the server • node.js (V8) • narwhal.js (Rhino & friends) • In your database • if it’s CouchDBTuesday, March 22, 2011
  3. 3. eschew evalTuesday, March 22, 2011
  4. 4. how prototypicalTuesday, March 22, 2011
  5. 5. function Person(){} Person.prototype.getName = function(){ return this.name; }; function Me(){ this.name = "John Resig"; } Me.prototype = new Person(); var me = new Me(); me.getName(); // "John Resig" http://ejohn.org/apps/learn/#78Tuesday, March 22, 2011
  6. 6. getting it right buy the bookTuesday, March 22, 2011
  7. 7. Meet Douglas Crockford • author of JavaScript: the Good Parts • minified JS education • works at Yahoo! • checkout YUI Theatre • also javascript.crockford.comTuesday, March 22, 2011
  8. 8. He begat JSLint • cleans up your JS • will hurt your feelingsTuesday, March 22, 2011
  9. 9. (function() { four = eval(2+2); var eight = multiply(four, 2); function multiply(n,y) { return n*y } if (typeof eight == string) { console.log(fale); } });Tuesday, March 22, 2011
  10. 10. Problem at line 2 character 8: eval is evil. (function() { multiply was used before it was defined. four = eval(2+2); var eight = multiply(four, 2); function multiply(n,y) { return n*y Expected ; and instead saw }. } if (typeof eight == string) { console.log(fale); Expected === and instead saw ==. } }); Do not wrap function literals in parens unless they are Expected an assignment or function ca# and to be immediately invoked. instead saw an expression.Tuesday, March 22, 2011
  11. 11. see?Tuesday, March 22, 2011
  12. 12. JSLint: finds...stuff • Undefined Vars & Functions • Globals/Members lists • Semicolon checking • clean blocks • checks for break in switchTuesday, March 22, 2011
  13. 13. more stuff • singe var at the top • no more with • better comparisons • == vs === • eval is Evil (but you knew that already)Tuesday, March 22, 2011
  14. 14. Awful Parts • Global Variables • Scope (confusing/misleading variable scope) • Semicolon Insertion • Reserved WordsTuesday, March 22, 2011
  15. 15. Reserved Words • boolean • final • short • break • finally • switch • byte • float • this • case • for • throw • catch • function • true • char • if • try • continue • in • typeof • default • instanceof • var • delete • int • void • do • long • while • double • new • with • else • null • false • returnTuesday, March 22, 2011
  16. 16. Resources • jslint.com • jshint.com • ejohn.org/apps/learn/Tuesday, March 22, 2011

×