Re: Better event listeners

On 10/01/2013 14:38 , brandon.wallace@yahoo.com wrote:
>> I meant that, if an object with methods were returned, the method
>> should be named "off" as opposed to "cancel" or "stop" etc. Agreed
>> that a function instead of an object is more elegant, however.
>
> I believe it has been mentioned that an object leaves the door open
> for future enhancements.  Returning only a function limits your
> options for future enhancements.

Actually, just because it's a function doesn't mean it can't be extended:

var obj = function () { console.log("stop"); };
obj.start = function () { console.log("start"); };
obj();
obj.start();

Whether that's elegant is another question.

-- 
Robin Berjon - http://berjon.com/ - @robinberjon

Received on Thursday, 10 January 2013 15:19:09 UTC