Chain local functions as member functions in JS