JSLent: give it up for JavaScript

  • 940 views
Uploaded on

Simple ways to improve your JavaScript code.

Simple ways to improve your JavaScript code.

More in: Self Improvement
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Be the first to comment
    Be the first to like this
No Downloads

Views

Total Views
940
On Slideshare
0
From Embeds
0
Number of Embeds
2

Actions

Shares
Downloads
3
Comments
0
Likes
0

Embeds 0

No embeds

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
    No notes for slide

Transcript

  • 1. JSLent give it up for JavaScriptTuesday, March 22, 2011
  • 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. eschew evalTuesday, March 22, 2011
  • 4. how prototypicalTuesday, March 22, 2011
  • 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. getting it right buy the bookTuesday, March 22, 2011
  • 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. He begat JSLint • cleans up your JS • will hurt your feelingsTuesday, March 22, 2011
  • 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. 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. see?Tuesday, March 22, 2011
  • 12. JSLint: finds...stuff • Undefined Vars & Functions • Globals/Members lists • Semicolon checking • clean blocks • checks for break in switchTuesday, March 22, 2011
  • 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. Awful Parts • Global Variables • Scope (confusing/misleading variable scope) • Semicolon Insertion • Reserved WordsTuesday, March 22, 2011
  • 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. Resources • jslint.com • jshint.com • ejohn.org/apps/learn/Tuesday, March 22, 2011