Slideshow transcript
Slide 1: Metaprogramming JavaScript Dan Webb (dan@danwebb.net)
Slide 2: What? “ the writing of computer programs that write or manipulate other programs (or themselves) as their data”
Slide 3: With JavaScript?! ★ Small and fiesty but widely misunderstood ★ Relies on few but powerful constructs ★ You can work with functions, arguments, built-ins types and mechanisms like inheritance at runtime ★ Techniques underpin many JS libraries
Slide 4: JavaScript Exposed: Objects Out Of Control!
Slide 5: Play along!
Slide 6: 4 building blocks
Slide 7: (Nearly) everything is a hash
Slide 8: number string boolean undefined
Slide 9: everything else is an Object
Slide 11: This works with any object
Slide 13: Expandos: a special case
Slide 17: Inspecting objects
Slide 20: Inspecting types
Slide 24: Wha?!
Slide 26: First typeof then instanceof
Slide 27: Functions are Objects
Slide 29: 'Methods' are just functions that are assigned to a property of an object
Slide 38: arguments
Slide 42: Functions can return other functions
Slide 45: Closure
Slide 46: Back to wikipedia... “ A closure occurs when a function is defined within another function, and the inner function refers to local variables of the outer function.
Slide 49: Why is that useful?
Slide 53: Functions can be used to make objects
Slide 55: Constructor functions are just functions
Slide 56: The magic is in the new operator
Slide 60: inheritance
Slide 67: The point is: its all just functions, objects and properties
Slide 68: We can hack it all.
Slide 69: So what can you do with this stuff?
Slide 70: Patch holes in bad implementations
Slide 73: Self optimising code
Slide 76: Pretty APIs
Slide 79: Domain Specific Languages
Slide 80: DOMBuilder http://danwebb.net/lowpro
Slide 84: DIY language features
Slide 85: John Resig's method overloading http://ejohn.org/blog/javascript-method-overloading/
Slide 89: Prototype 1.6 Classes http://prototypejs.org/learn/class-inheritance
Slide 92: and a lot more...
Slide 93: Looking back... ★ JavaScript is small but totally flexible ★ A handful of techniques provide everything you need ★ It's all about objects, properties and functions ★ Don't worry if its not all sunk in. Have a play around. Slides will be available.
Slide 94: Coming Soon...



Add a comment on Slide 1
If you have a SlideShare account, login to comment; else you can comment as a guest- Favorites & Groups
Showing 1-50 of 36 (more)