The document discusses JavaScript and its uses in browsers, on servers with Node.js and Narwhal.js, and in databases like CouchDB. It discusses prototypical inheritance in JavaScript and recommends buying Douglas Crockford's book "JavaScript: The Good Parts" to learn JavaScript properly. It introduces Crockford and his creation of JSLint to clean up JavaScript code and validate best practices. JSLint finds issues like undefined variables and functions, missing semicolons, and discourages the use of eval. The document also notes some of the "Awful Parts" of JavaScript like global variables, scope issues, and reserved words.
Reinventing Corporate Philanthropy_ Strategies for Meaningful Impact by Leko ...
JSLent: give it up for JavaScript
1. JSLent
give it up for JavaScript
Tuesday, 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 CouchDB
Tuesday, 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/#78
Tuesday, 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.com
Tuesday, March 22, 2011
8. He begat JSLint
• cleans up your JS
• will hurt your feelings
Tuesday, 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
12. JSLint: finds...stuff
• Undefined Vars & Functions
• Globals/Members lists
• Semicolon checking
• clean blocks
• checks for break in switch
Tuesday, 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 Words
Tuesday, 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 • return
Tuesday, March 22, 2011