1 / 12

JavaScript Deep Dive

JavaScript Deep Dive. This might stin g a little…. Jason Offutt Software Engineer Central Christian Church Email: jason.offutt@centralaz.com Twitter: @ jasonoffutt. Understanding ‘this’. To understand ‘this’, we need to start with understanding function invocation Calling a function

jody
Download Presentation

JavaScript Deep Dive

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. JavaScript Deep Dive This might sting a little… Jason Offutt Software Engineer Central Christian Church Email: jason.offutt@centralaz.com Twitter: @jasonoffutt

  2. Understanding ‘this’ • To understand ‘this’, we need to start with understanding function invocation • Calling a function • Accessing a function’s value • As a set of instructions

  3. Function call shorthand • The function primitive actually has ‘call’ and ‘apply’ methods • Allows you to directly manipulate the contextual value of ‘this’

  4. Closures & Scope Stay with me here…

  5. Block Scope? Nope • Code blocks (e.g. – if, while, for, switch, etc) have no scope • Only functions provide scope

  6. Lexical Scope? Yep • A fancy way of describing the physical placement of a function within written source code • The scope of the containing function gets associated with variables, etc

  7. Closures • A closure is a reference to a function • One is created every time you declare a function • Variable values and surrounding context are bound by reference to the function • They are not immediately deallocated from memory when they lose scope

  8. How is any of this useful? • Write clean/reusable JavaScript • Ensure your code won’t break other modules • Avoid shooting yourself in the foot

  9. Namespacing • Building off of closures • Allows you to keep your code more modular • Adds additional ways to avoid collisions with external code

  10. Popular approaches • Global Object • Singleton • Cascading

  11. Prototypes • Prototypes provide hooks into the JavaScript object model • Allow you to create and override instance methods and properties on objects

  12. Questions? • For a copy of these slides, my notes and code samples, head over to Github: • https://github.com/JasonOffutt/RefreshCache2011

More Related