event.memo inconsistency

50 views
Skip to first unread message

Cédric Bertolini

unread,
Jun 10, 2010, 10:05:37 AM6/10/10
to Prototype: Core
Hi all,

I'm posting a new subject to avoid thread necromancy, but this message
refers to a brief discussion that took place here in March 2010.

Since Prototype1.7 is approaching, I looked at the CHANGELOG and
didn't see anything related to this topic.

The doc on event.memo (http://api.prototypejs.org/dom/event/fire/)
says

memo – Metadata for the event. Will be accessible through the event's
memo property.

If I fire an event without providing any memo, event.memo will be set
to an empty object. Why not, but it should be in the documentation.

But when I fire an event with a string as the memo argument, I will
sometimes lose this string because it will be replaced by an empty
object! This will happen everytime the string argument is an empty
string, because Prototype checks the boolean value of the memo
argument!

So basically, I have an API that let me use a primitive String as
argument for event.memo, but will sometimes replace it with something
completly different.

I suggest one of two corrections:

Either Event#fire sets the memo argument to an empty object only if
said argument is undefined:

< event.memo = memo || {};
> event.memo = Object.isUndefined(memo) ? {} : memo;

,or Event#fire requires the memo is an Object if it is not undefined:


< event.memo = memo || {};
> event.memo = Object.isUndefined(memo) ? {} : memo;
> if(Object.isString(memo) || Object.isNumber(memo)

Cédric Bertolini

unread,
Jun 11, 2010, 10:56:01 AM6/11/10
to Prototype: Core
My message was somehow truncated yesterday, and the "patch" line
format is mistaken for a "usenet quote" format. Sorry about that.

Element#fire takes an object argument as memo. If the argument is
missing, an empty object is used instead. The problematic case is when
the argument is neither undefined nor an object : a primitive string
or number. In these cases, Element#fire silently discards the provided
argument and uses an empty object. I think this is bad design and
should be corrected.

Thanks for your time.
Reply all
Reply to author
Forward
0 new messages