javascript deep dive

Download JavaScript Deep Dive

Post on 13-Feb-2016

43 views

Category:

Documents

1 download

Embed Size (px)

DESCRIPTION

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 - PowerPoint PPT Presentation

TRANSCRIPT

Slide 1

JavaScript Deep DiveThis might sting a littleJason OffuttSoftware EngineerCentral Christian Church

Email: jason.offutt@centralaz.comTwitter: @jasonoffutt#RefreshCacheUnderstanding thisTo understand this, we need to start with understanding function invocationCalling a functionAccessing a functions valueAs a set of instructionsFunction call shorthandThe function primitive actually has call and apply methodsAllows you to directly manipulate the contextual value of thisClosures & ScopeStay with me here

Block Scope? NopeCode blocks (e.g. if, while, for, switch, etc) have no scopeOnly functions provide scopeLexical Scope? YepA fancy way of describing the physical placement of a function within written source codeThe scope of the containing function gets associated with variables, etcClosuresA closure is a reference to a functionOne is created every time you declare a functionVariable values and surrounding context are bound by reference to the functionThey are not immediately deallocated from memory when they lose scopeHow is any of this useful?Write clean/reusable JavaScriptEnsure your code wont break other modulesAvoid shooting yourself in the foot

NamespacingBuilding off of closuresAllows you to keep your code more modularAdds additional ways to avoid collisions with external codePopular approachesGlobal ObjectSingletonCascadingPrototypesPrototypes provide hooks into the JavaScript object modelAllow you to create and override instance methods and properties on objectsQuestions?For a copy of these slides, my notes and code samples, head over to Github:https://github.com/JasonOffutt/RefreshCache2011