• Share
  • Email
  • Embed
  • Like
  • Save
  • Private Content
Effective JavaScript
 

Effective JavaScript

on

  • 4,057 views

Slides from the Effective JavaScript talk at Palm DevDay.

Slides from the Effective JavaScript talk at Palm DevDay.

Statistics

Views

Total Views
4,057
Views on SlideShare
4,029
Embed Views
28

Actions

Likes
6
Downloads
130
Comments
0

2 Embeds 28

http://www.slideshare.net 27
http://palmplatform.com 1

Accessibility

Categories

Upload Details

Uploaded via as Apple Keynote

Usage Rights

© All Rights Reserved

Report content

Flagged as inappropriate Flag as inappropriate
Flag as inappropriate

Select your reason for flagging this presentation as inappropriate.

Cancel
  • Full Name Full Name Comment goes here.
    Are you sure you want to
    Your message goes here
    Processing…
Post Comment
Edit your comment
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • No block scope. In general you reference enclosing functions and their arguments until you reach the global scope. With is an exception. <br />
  • This isn&#x2019;t as true in v8. <br />
  • Referencing a is 4 steps away! <br />
  • If something isn&#x2019;t defined in the object in your with statement, you create a global. If it is, you overwrite that property. It&#x2019;s difficult to tell from reading the code how an assignment might affect the program. <br />
  • <br />
  • <br />
  • <br />
  • And you can combine the two! <br />
  • This avoids a step on the scope chain. <br />
  • Minimize your code, don&#x2019;t keep functions around that are one-offs. On the other hand, this function is recreated every time. <br />
  • As always with closures, watch for memory leaks. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • Be careful though, unlike other languages with getters and setters, Javascript won&#x2019;t warn you if you access an undefined property. It&#x2019;ll just return undefined. <br />
  • <br />
  • <br />
  • <br />
  • <br />
  • <br />

Effective JavaScript Effective JavaScript Presentation Transcript

  • Effective JavaScript Justin Tulloss Sr. Software Engineer April 24, 2010
  • Overview • JavaScript language properties • Effective closures • Effective objects • Interacting with the DOM • ECMAScript 5 • v8 optimizations
  • Prototypes
  • Assigning to a Prototype
  • Altering a Prototype
  • Altering a Prototype Faster
  • Deriving an Object from Another Object
  • Deriving an Object with Object.create
  • Scope Resolution
  • What Is in the Resolution Chain? Functions dictate scope (with a few exceptions) • Local variables • Arguments • Enclosing function scopes • With Statement • Global
  • Each Step Is Like a Property Access locals.arguments.scope1Locals.scope1Args.globals
  • Example
  • Don’t Use with
  • Effective Closures
  • The Power of Closures With great power comes great responsibility • Reduce typing • Make code cleaner • Provide some privacy • Sometimes they make things fast • Magic (AKA functional)
  • Building Objects with Closures
  • Same Thing Works for Constructors
  • Avoiding bind in Asynchronous Operations
  • Avoiding Unnecessary Methods
  • Memoization
  • Effective Objects
  • Using Objects Effectively • First, do what makes sense—don’t over-optimize • Every property access is slow • Breadth not depth • Use object literals • Make shortcuts • Inspectable
  • Use Object Literals Bad Good
  • Interacting with the DOM
  • Don’t
  • DOM Tips • Watch out for closures referencing nodes • These can leak • Reference nodes anyway • Using a reference is much faster than looking up a node • innerHTML is generally faster than the DOM API
  • ECMAScript 5
  • Exciting New Features • Function.prototype.bind • Object.create • Getters/setters • String.prototype.trim
  • Getters and Setters
  • v8 Optimizations
  • v8 Optimizations • Don’t use delete • Use object literals • Avoid altering objects after creating them • Don’t use eval
  • If it’s hard in C, it’s slow in
  • Q &A