How do I assign a function to the property of a Javascript object?