Upgrade to Pro — share decks privately, control downloads, hide ads and more …

New Rules For JavaScript

New Rules For JavaScript

Video Coverage: http://www.youtube.com/watch?v=S4cvuuq3OKY

I bet you've been writing JS for years and you think you're pretty good at it. I bet you think you know all about how functions create closured scope, and how `this` gets bound, and even how `.prototype` works. Or, rather, you probably don't care because your framework or library takes care of all that for you.

JavaScript is generally considered one of the most misunderstood (and maligned) languages of the modern programming era. And there's good reason for that, because most developers who write JS never actually deeply *know* how the language works. They blame all their WTFs on language bugs, instead of the shortcomings in understanding.

This talk re-visits some of the "tough parts" of the language by declaring "New Rules" (Bill Maher style) for the language. For instance: "new rule: stop using `this` until you really understand how it gets assigned"

This talk is hard-core on coding and expects a solid understanding of the language.

Kyle Simpson

October 04, 2013
Tweet

More Decks by Kyle Simpson

Other Decks in Programming

Transcript

  1. == checks value === checks value and type == allows

    coercion === disallows coercion
  2. “When comparing any of the following values, always use the

    === or !== operators, which do not do type coercion: 0 “” undefined null false true If you want the type coercion, then use the short form...” — “The Good Parts”
  3. this won’t work until ES6!? this won’t even work in

    ES6! this can work right now in ES3!
  4. 4 steps to this 1. is the call-site new-invoked? use

    that 2. is the call-site binding overridden with call/apply? use that 3. is the call-site on an owned-object? use that 4. otherwise, use global (except strict mode)
  5. don’t try to be so clever and mix-n-match this-style with

    closure-style code pick one or the other. use it.