Metaprogramming JavaScript

60,982 views
58,389 views

Published on

As presented at @media Ajax in London on the 20th November 2007.

Published in: Technology
7 Comments
152 Likes
Statistics
Notes
  • JavaScript: Crash Course - The Ultimate Beginner's Course to Learning JavaScript Programming in Under 12 Hours --- http://amzn.to/1SaRAjU
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • JavaScript and JQuery: Interactive Front-End Web Development --- http://amzn.to/22vHpLC
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • A Smarter Way to Learn JavaScript: The new approach that uses technology to cut your effort in half --- http://amzn.to/1UdwapY
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • great!
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
  • good job
       Reply 
    Are you sure you want to  Yes  No
    Your message goes here
No Downloads
Views
Total views
60,982
On SlideShare
0
From Embeds
0
Number of Embeds
1,355
Actions
Shares
0
Downloads
1,863
Comments
7
Likes
152
Embeds 0
No embeds

No notes for slide

Metaprogramming JavaScript

  1. Metaprogramming JavaScript Dan Webb (dan@danwebb.net)
  2. What? “ the writing of computer programs that write or manipulate other programs (or themselves) as their data”
  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
  4. JavaScript Exposed: Objects Out Of Control!
  5. Play along!
  6. 4 building blocks
  7. (Nearly) everything is a hash
  8. number string boolean undefined
  9. everything else is an Object
  10. This works with any object
  11. Expandos: a special case
  12. Inspecting objects
  13. Inspecting types
  14. Wha?!
  15. First typeof then instanceof
  16. Functions are Objects
  17. 'Methods' are just functions that are assigned to a property of an object
  18. arguments
  19. Functions can return other functions
  20. Closure
  21. 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.
  22. Why is that useful?
  23. Functions can be used to make objects
  24. Constructor functions are just functions
  25. The magic is in the new operator
  26. inheritance
  27. The point is: its all just functions, objects and properties
  28. We can hack it all.
  29. So what can you do with this stuff?
  30. Patch holes in bad implementations
  31. Self optimising code
  32. Pretty APIs
  33. Domain Specific Languages
  34. DOMBuilder http://danwebb.net/lowpro
  35. DIY language features
  36. John Resig's method overloading http://ejohn.org/blog/javascript-method-overloading/
  37. Prototype 1.6 Classes http://prototypejs.org/learn/class-inheritance
  38. and a lot more...
  39. 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.
  40. Coming Soon...

×