Successfully reported this slideshow.
We use your LinkedIn profile and activity data to personalize ads and to show you more relevant ads. You can change your ad preferences anytime.
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,337 views

Published on

Simple ways to improve your JavaScript code.

Published in: Self Improvement
  • Be the first to comment

  • Be the first to like this

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

×