JavaScript: Functional Programming for JavaScript Developers
by Ved Antani, Simon Timms, Dan Mantyla
Live post processing
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 ...
Become an O’Reilly member and get unlimited access to this title plus top books and audiobooks from O’Reilly and nearly 200 top publishers, thousands of courses curated by job role, 150+ live events each month,
and much more.
Read now
Unlock full access