Code for first class functions in js