Now that you have seen how to construct a self-reproducing program, you may also enjoy the following items. In particular, the last item in the list gives rise to a Generalized Challenge.
Generalized Challenge: Write the preceding programs, by writing a program that takes as input the JavaScript definition of function f and that outputs a JavaScript program Pf that outputs this f applied to Pf.