JavaScript:   The Good Parts Douglas Crockford Yahoo! Inc. http://www.crockford.com/codecamp/
The World's Most Misunderstood Programming Language
A language of many contrasts.
The broadest range of programmer skills of any programming language. From computer scientists  to cut-n-pasters  and everyone in between.
Complaints "JavaScript is not a language I know." "The browser programming experience is awful." "It's not fast enough." "The language is just a pile of mistakes."
Hidden under a huge steaming pile of good intentions and blunders is an elegant, expressive programming language. JavaScript has good parts.
JavaScript is succeeding very well in an environment where Java was a total failure.
Influences Self prototypal inheritance dynamic objects Scheme lambda loose typing Java syntax conventions Perl regular expressions
Bad Parts Global Variables + adds and concatenates Semicolon insertion typeof with and eval phony arrays == and != false, null, undefined, NaN
Transitivity? What's That? '' == '0'  // false 0 == ''  // true 0 == '0'  // true false == 'false'  // false false == '0'  // true false == undefined // false false == null  // false null == undefined  // true " \t\r\n " == 0  // true
value = myObject[name]; if (value  == null ) { alert(name + ' not found.'); } Two errors that cancel each other out.
value = myObject[name]; if (value  === undefined ) { alert(name + ' not found.'); }
Good features that interact badly Objects can inherit from other objects. Functions can be members of objects. for..in statement mixes inherited functions with the desired data members.
for in is troublesome Design question: Should for..in do a shallow skim or a deep dredge? Decision: Deep dredge. The programmer must explicitly filter out the deep members. Except: They didn't tell anybody! Consequence: Lots of confusion about how to use for..in.
for in is troublesome Better Decision: Don't release the language broadly until we have enough experience to have confidence that we made the right choice. Historical Context: Getting it right at Netscape wasn't an option.
Bad Heritage Blockless statements if (foo) bar(); Expression statements foo; Floating point arithmetic 0.1 + 0.2 !== 0.3 ++ and -- switch
Good Parts Lambda Dynamic Objects Loose Typing Object Literals
Inheritance Inheritance is object-oriented code reuse. Two Schools: Classical Prototypal
Prototypal Inheritance Class-free. Objects inherit from objects. An object contains a  link  to another object: Delegation. Differential Inheritance. var newObject =  Object.create(oldObject); newObject oldObject __proto__
Prototypal Inheritance if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; }
new The  new  operator is  required  when calling a Constructor function. If  new  is omitted, the global object is clobbered by the constructor. There is no compile-time or run-time warning.
Global var  names  = ['zero', 'one', 'two',  'three', 'four', 'five', 'six',  'seven', 'eight', 'nine']; var  digit_name  =  function (n) { return  names [n]; }; alert( digit_name (3));  // 'three'
Slow var  digit_name  =  function (n) {   var  names  = ['zero', 'one', 'two',  'three', 'four', 'five', 'six',  'seven', 'eight', 'nine']; return  names [n]; }; alert( digit_name (3));  // 'three'
Closure var  digit_name  = (function () { var  names  = ['zero', 'one', 'two',  'three', 'four', 'five', 'six',  'seven', 'eight', 'nine']; return  function (n) { return  names [n]; }; } ()) ; alert( digit_name (3));  // 'three'
A Module Pattern var singleton = ( function () { var  privateVariable ; function  privateFunction (x) { ... privateVariable ... } return  { firstMethod: function (a, b) { ... privateVariable ... }, secondMethod: function (c) { ... privateFunction ()... } } ; }() );
Module pattern is easily transformed into a powerful constructor pattern.
Power Constructors Make an object. Object literal new Object.create call another power constructor
Power Constructors Make an object. Object literal,  new ,  Object.create , call another power constructor Define some variables and functions.  These become private members.
Power Constructors Make an object. Object literal,  new ,  Object.create , call another power constructor Define some variables and functions.  These become private members. Augment the object with privileged methods.
Power Constructors Make an object. Object literal,  new ,  Object.create , call another power constructor Define some variables and functions.  These become private members. Augment the object with privileged methods. Return the object.
Step One function myPowerConstructor(x) { var that = otherMaker(x); }
Step Two function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); }
Step Three function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); that.priv = function () { ... secret x that ... }; }
Step Four function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); that.priv = function () { ... secret x that ... }; return that; }
Closure A function object contains A function (name, parameters, body) A reference to the environment in which it was created (context). This is a very good thing.
Style Isn't Subjective block { .... } Might work well in other languages block  { .... } Works well in JavaScript
Style Isn't Subjective return { ok: false }; SILENT ERROR! return { ok: true }; Works well in JavaScript
Style Isn't Subjective return { ok: false };
Style Isn't Subjective return ; // semicolon insertion { ok: false };
Style Isn't Subjective return; {   // block ok: false } ;
Style Isn't Subjective return; {  ok:  false  // label };
Style Isn't Subjective return; {  // useless ok:  false   // expression };  // statement
Style Isn't Subjective return; {  ok: false ; // semicolon };  // insertion
Style Isn't Subjective return; {  ok: false; } ;   // empty statement
Style Isn't Subjective return; {   // unreachable statement ok: false; }
Style Isn't Subjective return { ok: false }; Bad style return; { ok: false; } Bad results
Working with the Grain
A Personal Journey Beautiful Code
JSLint JSLint defines a professional subset of JavaScript. It imposes a programming discipline that makes me much more confident in a dynamic, loosely-typed environment. http://www.JSLint.com/
WARNING! JSLint will hurt your feelings.
Unlearning Is  Really Hard Perfectly Fine == Faulty
It's not ignorance does so much damage; it's knowin' so derned much that ain't so.  Josh Billings
The Very Best Part: Stability No new design errors  since 1999!
Coming Soon [ES3.1] ECMAScript Fifth Edition Corrections Reality Support for object hardening Strict mode for reliability "use strict"; Waiting on implementations
Not Coming Soon [ES4] This project has been cancelled. Instead, [ES-Harmony]. So far, this project has no defined goals or rules.
Safe Subsets The most effective way to make this language better is to make it smaller. FBJS Caja & Cajita Web Sandbox ADsafe The next edition of ECMAScript might include a secure formal subset.
The Good Parts Your JavaScript application can reach a potential audience of billions. If you avoid the bad parts, JavaScript works really well. There is some brilliance in it. It is possible to write good programs with JavaScript.
 

More Related Content

PPT
Goodparts
PPS
Master in javascript
PDF
Grooming with Groovy
PPT
name name2 n2
PPT
Ruby for Perl Programmers
PPT
ppt9
PPT
name name2 n2.ppt
PPT
name name2 n
Goodparts
Master in javascript
Grooming with Groovy
name name2 n2
Ruby for Perl Programmers
ppt9
name name2 n2.ppt
name name2 n

What's hot (13)

PPT
ppt18
PPTX
Clean Code Principles
PPS
Coding Best Practices
PPTX
JS Fest 2018. Douglas Crockford. The Better Parts
KEY
Thinking Like a Programmer
PPTX
Groovy Programming Language
PDF
Effective Scala (SoftShake 2013)
PDF
Clean Code
PPT
JavaScript: The Language
PPTX
Clean Code: Stop wasting my time
PPTX
Polymorphism in C++
KEY
Java Building Blocks
PDF
Ruby for Java Developers
ppt18
Clean Code Principles
Coding Best Practices
JS Fest 2018. Douglas Crockford. The Better Parts
Thinking Like a Programmer
Groovy Programming Language
Effective Scala (SoftShake 2013)
Clean Code
JavaScript: The Language
Clean Code: Stop wasting my time
Polymorphism in C++
Java Building Blocks
Ruby for Java Developers
Ad

Viewers also liked (20)

PPTX
David Wei And Changhao Jiang Presentation
PPT
Chapter 3 notes 1
PPT
The Knoll 2
PDF
Bill Scott Presentation
PDF
Taylor De Jongh Qualifications Mar 2010
PDF
_s v. genesis
PPT
Present simple-affirmative
DOC
Aplicaciones moviles
PDF
Kcd226 Sistem Operasi Lecture03
PDF
Colin Clark Accessible U Is With J Query And Infusion[1]
DOC
Beginningyearparentpacket
PPT
Nitin\'s Business Intelligence Portfolio
PDF
Ted Husted Presentation Testing Ajax Applications Ae2009
DOC
Test Analyst 3 + Yrs Manual Automation Theme
PDF
Past References
PDF
Generaciones de las Computadoras
PDF
High Performance Green Building: What is it worth?
PPT
Earth And Moon Jeopardy Review
PDF
Susd0001 Nicolas Carbone Individual Assignment (2)
PDF
McCormick Mobile Media - Mobile Giving
David Wei And Changhao Jiang Presentation
Chapter 3 notes 1
The Knoll 2
Bill Scott Presentation
Taylor De Jongh Qualifications Mar 2010
_s v. genesis
Present simple-affirmative
Aplicaciones moviles
Kcd226 Sistem Operasi Lecture03
Colin Clark Accessible U Is With J Query And Infusion[1]
Beginningyearparentpacket
Nitin\'s Business Intelligence Portfolio
Ted Husted Presentation Testing Ajax Applications Ae2009
Test Analyst 3 + Yrs Manual Automation Theme
Past References
Generaciones de las Computadoras
High Performance Green Building: What is it worth?
Earth And Moon Jeopardy Review
Susd0001 Nicolas Carbone Individual Assignment (2)
McCormick Mobile Media - Mobile Giving
Ad

Similar to Douglas Crockford Presentation Goodparts (20)

PDF
Javascript status 2016
KEY
Douglas Crockford - Programming Style and Your Brain
PDF
Section 8 Programming Style and Your Brain: Douglas Crockford
PPTX
All of Javascript
PPTX
All of javascript
PDF
JavaScript Interview Questions PDF By ScholarHat
PDF
JavaScript: Core Part
PPT
Ajax and JavaScript Bootcamp
PDF
Go Beyond Higher Order Functions: A Journey into Functional Programming
PPTX
Advanced javascript from zero to hero in this PPT
PPT
2007 09 10 Fzi Training Groovy Grails V Ws
PPT
Java script unleashed
PDF
OOPS JavaScript Interview Questions PDF By ScholarHat
PPT
Java Intro
PPT
Node.js: CAMTA Presentation
PPT
Javascript quiz. Questions to ask when recruiting developers.
PPT
Groovy Update - JavaPolis 2007
KEY
JavaScript Neednt Hurt - JavaBin talk
PDF
Google Interview Questions By Scholarhat
Javascript status 2016
Douglas Crockford - Programming Style and Your Brain
Section 8 Programming Style and Your Brain: Douglas Crockford
All of Javascript
All of javascript
JavaScript Interview Questions PDF By ScholarHat
JavaScript: Core Part
Ajax and JavaScript Bootcamp
Go Beyond Higher Order Functions: A Journey into Functional Programming
Advanced javascript from zero to hero in this PPT
2007 09 10 Fzi Training Groovy Grails V Ws
Java script unleashed
OOPS JavaScript Interview Questions PDF By ScholarHat
Java Intro
Node.js: CAMTA Presentation
Javascript quiz. Questions to ask when recruiting developers.
Groovy Update - JavaPolis 2007
JavaScript Neednt Hurt - JavaBin talk
Google Interview Questions By Scholarhat

More from Ajax Experience 2009 (17)

PPT
Adam Peller Interoperable Ajax Tools And Mashups
PPTX
Eric Beland Ajax Load Testing Considerations
PPTX
Chanhao Jiang And David Wei Presentation Quickling Pagecache
PPT
Jason.O Keefe.Genuitec.Presentation.Final
PPTX
Jenny Donnelly
PPTX
Scott Isaacs Presentationajaxexperience (Final)
PPT
Sergey Ilinsky Presentation Ample Sdk
PPT
Chris Williams Presentation Dissident
PPT
Andrew Sutherland Presentation
PDF
Ted Husted Api Doc Smackdown Ae2009
PDF
Patrick Lightbody Presentation Tae Slides
PPT
Laurens Van Den Oever Xopus Presentation
PPT
Jon Trelfa Presentation From Desktop To Web – Getting It Right
PPTX
Joe Mc Cann Tae Aria Presentation
PPT
Douglas Crockford Presentation Jsonsaga
PDF
Brian Le Roux Presentation Introducing Phone Gap
PDF
Ted Husted Presentation Testing The Testers Ae2009
Adam Peller Interoperable Ajax Tools And Mashups
Eric Beland Ajax Load Testing Considerations
Chanhao Jiang And David Wei Presentation Quickling Pagecache
Jason.O Keefe.Genuitec.Presentation.Final
Jenny Donnelly
Scott Isaacs Presentationajaxexperience (Final)
Sergey Ilinsky Presentation Ample Sdk
Chris Williams Presentation Dissident
Andrew Sutherland Presentation
Ted Husted Api Doc Smackdown Ae2009
Patrick Lightbody Presentation Tae Slides
Laurens Van Den Oever Xopus Presentation
Jon Trelfa Presentation From Desktop To Web – Getting It Right
Joe Mc Cann Tae Aria Presentation
Douglas Crockford Presentation Jsonsaga
Brian Le Roux Presentation Introducing Phone Gap
Ted Husted Presentation Testing The Testers Ae2009

Recently uploaded (20)

PPTX
Continents English presentation 2025.pptx
PPTX
Discover Brazil Your Ultimate Tour Package.pptx
PDF
96-Hour Dubai Transit Visa – Everything You Need to Know in 2025.pdf
DOCX
Everest Base Camp Trek in October: A Complete Guide
PPTX
Manuel Antonio National Park – Explore with Mapache Tours
PDF
Cruise Tourism - Introduction to Cruise Sector
PPTX
Travel Portal Development Services | XML API integrationpptx
PDF
Planning Your First Kumbh Yatra? Here’s What You Need
PDF
Giants of Betel Nut Island - KohMak - PUBLISHED with EZdive
PDF
Raja Ampat: Fishopcalpse in the Last Paradise - PUBLISHED with DYK.net & DYK....
PPTX
🐅 Wildlife Tours in India – A Journey.pptx
PPTX
API Integration Services | Travel Booking API
PPTX
Best Turkey Tours Packages to Explore the Destination in Four Days.pptx
PDF
Dining Etiquette & Service Excellence Training
PPTX
On Safari in India in Search of the Bengal Tiger
PDF
Dining Etiquette & Service Excellence Training part 2
DOC
退学买PNW毕业证学历认证,冷泉港实验室毕业证学位证书学历证书
PPSX
Silver Cave, Yangshuo, Guangxi, CN. (中國 廣西陽朔 銀子岩).ppsx
PPTX
Sacred Madhya Pradesh Tours – Ujjain, Omkareshwar & Beyond with Antriksh Travel
PDF
top places to visit in nepal: Best Treks, Cities, and Natural Wonders
Continents English presentation 2025.pptx
Discover Brazil Your Ultimate Tour Package.pptx
96-Hour Dubai Transit Visa – Everything You Need to Know in 2025.pdf
Everest Base Camp Trek in October: A Complete Guide
Manuel Antonio National Park – Explore with Mapache Tours
Cruise Tourism - Introduction to Cruise Sector
Travel Portal Development Services | XML API integrationpptx
Planning Your First Kumbh Yatra? Here’s What You Need
Giants of Betel Nut Island - KohMak - PUBLISHED with EZdive
Raja Ampat: Fishopcalpse in the Last Paradise - PUBLISHED with DYK.net & DYK....
🐅 Wildlife Tours in India – A Journey.pptx
API Integration Services | Travel Booking API
Best Turkey Tours Packages to Explore the Destination in Four Days.pptx
Dining Etiquette & Service Excellence Training
On Safari in India in Search of the Bengal Tiger
Dining Etiquette & Service Excellence Training part 2
退学买PNW毕业证学历认证,冷泉港实验室毕业证学位证书学历证书
Silver Cave, Yangshuo, Guangxi, CN. (中國 廣西陽朔 銀子岩).ppsx
Sacred Madhya Pradesh Tours – Ujjain, Omkareshwar & Beyond with Antriksh Travel
top places to visit in nepal: Best Treks, Cities, and Natural Wonders

Douglas Crockford Presentation Goodparts

  • 1. JavaScript: The Good Parts Douglas Crockford Yahoo! Inc. http://www.crockford.com/codecamp/
  • 2. The World's Most Misunderstood Programming Language
  • 3. A language of many contrasts.
  • 4. The broadest range of programmer skills of any programming language. From computer scientists to cut-n-pasters and everyone in between.
  • 5. Complaints "JavaScript is not a language I know." "The browser programming experience is awful." "It's not fast enough." "The language is just a pile of mistakes."
  • 6. Hidden under a huge steaming pile of good intentions and blunders is an elegant, expressive programming language. JavaScript has good parts.
  • 7. JavaScript is succeeding very well in an environment where Java was a total failure.
  • 8. Influences Self prototypal inheritance dynamic objects Scheme lambda loose typing Java syntax conventions Perl regular expressions
  • 9. Bad Parts Global Variables + adds and concatenates Semicolon insertion typeof with and eval phony arrays == and != false, null, undefined, NaN
  • 10. Transitivity? What's That? '' == '0' // false 0 == '' // true 0 == '0' // true false == 'false' // false false == '0' // true false == undefined // false false == null // false null == undefined // true " \t\r\n " == 0 // true
  • 11. value = myObject[name]; if (value == null ) { alert(name + ' not found.'); } Two errors that cancel each other out.
  • 12. value = myObject[name]; if (value === undefined ) { alert(name + ' not found.'); }
  • 13. Good features that interact badly Objects can inherit from other objects. Functions can be members of objects. for..in statement mixes inherited functions with the desired data members.
  • 14. for in is troublesome Design question: Should for..in do a shallow skim or a deep dredge? Decision: Deep dredge. The programmer must explicitly filter out the deep members. Except: They didn't tell anybody! Consequence: Lots of confusion about how to use for..in.
  • 15. for in is troublesome Better Decision: Don't release the language broadly until we have enough experience to have confidence that we made the right choice. Historical Context: Getting it right at Netscape wasn't an option.
  • 16. Bad Heritage Blockless statements if (foo) bar(); Expression statements foo; Floating point arithmetic 0.1 + 0.2 !== 0.3 ++ and -- switch
  • 17. Good Parts Lambda Dynamic Objects Loose Typing Object Literals
  • 18. Inheritance Inheritance is object-oriented code reuse. Two Schools: Classical Prototypal
  • 19. Prototypal Inheritance Class-free. Objects inherit from objects. An object contains a link to another object: Delegation. Differential Inheritance. var newObject = Object.create(oldObject); newObject oldObject __proto__
  • 20. Prototypal Inheritance if (typeof Object.create !== 'function') { Object.create = function (o) { function F() {} F.prototype = o; return new F(); }; }
  • 21. new The new operator is required when calling a Constructor function. If new is omitted, the global object is clobbered by the constructor. There is no compile-time or run-time warning.
  • 22. Global var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; var digit_name = function (n) { return names [n]; }; alert( digit_name (3)); // 'three'
  • 23. Slow var digit_name = function (n) { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return names [n]; }; alert( digit_name (3)); // 'three'
  • 24. Closure var digit_name = (function () { var names = ['zero', 'one', 'two', 'three', 'four', 'five', 'six', 'seven', 'eight', 'nine']; return function (n) { return names [n]; }; } ()) ; alert( digit_name (3)); // 'three'
  • 25. A Module Pattern var singleton = ( function () { var privateVariable ; function privateFunction (x) { ... privateVariable ... } return { firstMethod: function (a, b) { ... privateVariable ... }, secondMethod: function (c) { ... privateFunction ()... } } ; }() );
  • 26. Module pattern is easily transformed into a powerful constructor pattern.
  • 27. Power Constructors Make an object. Object literal new Object.create call another power constructor
  • 28. Power Constructors Make an object. Object literal, new , Object.create , call another power constructor Define some variables and functions. These become private members.
  • 29. Power Constructors Make an object. Object literal, new , Object.create , call another power constructor Define some variables and functions. These become private members. Augment the object with privileged methods.
  • 30. Power Constructors Make an object. Object literal, new , Object.create , call another power constructor Define some variables and functions. These become private members. Augment the object with privileged methods. Return the object.
  • 31. Step One function myPowerConstructor(x) { var that = otherMaker(x); }
  • 32. Step Two function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); }
  • 33. Step Three function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); that.priv = function () { ... secret x that ... }; }
  • 34. Step Four function myPowerConstructor(x) { var that = otherMaker(x); var secret = f(x); that.priv = function () { ... secret x that ... }; return that; }
  • 35. Closure A function object contains A function (name, parameters, body) A reference to the environment in which it was created (context). This is a very good thing.
  • 36. Style Isn't Subjective block { .... } Might work well in other languages block { .... } Works well in JavaScript
  • 37. Style Isn't Subjective return { ok: false }; SILENT ERROR! return { ok: true }; Works well in JavaScript
  • 38. Style Isn't Subjective return { ok: false };
  • 39. Style Isn't Subjective return ; // semicolon insertion { ok: false };
  • 40. Style Isn't Subjective return; { // block ok: false } ;
  • 41. Style Isn't Subjective return; { ok: false // label };
  • 42. Style Isn't Subjective return; { // useless ok: false // expression }; // statement
  • 43. Style Isn't Subjective return; { ok: false ; // semicolon }; // insertion
  • 44. Style Isn't Subjective return; { ok: false; } ; // empty statement
  • 45. Style Isn't Subjective return; { // unreachable statement ok: false; }
  • 46. Style Isn't Subjective return { ok: false }; Bad style return; { ok: false; } Bad results
  • 48. A Personal Journey Beautiful Code
  • 49. JSLint JSLint defines a professional subset of JavaScript. It imposes a programming discipline that makes me much more confident in a dynamic, loosely-typed environment. http://www.JSLint.com/
  • 50. WARNING! JSLint will hurt your feelings.
  • 51. Unlearning Is Really Hard Perfectly Fine == Faulty
  • 52. It's not ignorance does so much damage; it's knowin' so derned much that ain't so. Josh Billings
  • 53. The Very Best Part: Stability No new design errors since 1999!
  • 54. Coming Soon [ES3.1] ECMAScript Fifth Edition Corrections Reality Support for object hardening Strict mode for reliability "use strict"; Waiting on implementations
  • 55. Not Coming Soon [ES4] This project has been cancelled. Instead, [ES-Harmony]. So far, this project has no defined goals or rules.
  • 56. Safe Subsets The most effective way to make this language better is to make it smaller. FBJS Caja & Cajita Web Sandbox ADsafe The next edition of ECMAScript might include a secure formal subset.
  • 57. The Good Parts Your JavaScript application can reach a potential audience of billions. If you avoid the bad parts, JavaScript works really well. There is some brilliance in it. It is possible to write good programs with JavaScript.
  • 58.