use objects with functional methods in javascript