August 2016
Intermediate to advanced
635 pages
14h 5m
English
It should be apparent now that running toString over a function in JavaScript is a valid way to perform tasks. It seems odd but, really, writing code that emits other code is as old as Lisp or possibly older. When I first came across how dependency injection works in AngularJS, I was both disgusted at the hack and impressed by the ingenuity of the solution.
If it is possible to do dependency injection by interpreting code on the fly, then what more could we do with it? The answer is: quite a lot. The first thing that comes to mind is that you could write domain specific languages.
We talked about DSLs in Chapter 5, Behavioral Patterns, and even created a very simple one. With the ability to load and rewrite JavaScript, we can ...