#1064 enhancement
Ben Holland

Event memos don't correctly support values that evaluate to false

Reported by Ben Holland | May 27th, 2010 @ 01:05 PM

If you fire a custom event with a memo set to one of:

0
false
""

then the memo property is set to an empty object.

Offending line of Prototype 1.7RC2:

5650:    event.memo = memo || { };
suggested fix:
5650:    event.memo = (memo == undefined) ? { } : memo;

Though, in all honesty I'm not sure why an empty object was used in the first place. What would be wrong with passing memo as-is? I might deliberately choose to pass an undefined variable and not expect it to be transformed to an empty object.

Reproduce code:

document.observe("Badger:tickled", function(e) {
  alert("Memo is: " + Object.toJSON(e.memo));
  });
document.fire("Badger:tickled", 0);

Result: alert box shows "Memo is: {}"
Expected behaviour: alert box shows "Memo is 0"

Many thanks,
Ben

Comments and changes to this ticket

  • Dan Popescu

    Dan Popescu May 28th, 2010 @ 11:38 AM

    I think the whole idea is that memo should be an object.
    You can always use:

    document.observe("Badger:tickled", function(e) {
      alert("Memo is: " + Object.toJSON(e.memo));
      });
    document.fire("Badger:tickled", {value: 0});
    
  • Radoslav Stankov

    Radoslav Stankov May 28th, 2010 @ 01:45 PM

    • Tag changed from event, memo to needs:discussion, section:dom
    • State changed from “new” to “enhancement”

    Memo is ment to be used with plain Object. But it had never crossed my mind to just give some other kind Object, which is kind of cool.

    But the core members must say if this is worth 'fixing'.

Please Sign in or create a free account to add a new ticket.

With your very own profile, you can contribute to projects, track your activity, watch tickets, receive and update tickets through your email and much more.

New-ticket Create new ticket

Create your profile

Help contribute to this project by taking a few moments to create your personal profile. Create your profile ยป

The Prototype JavaScript library.

Shared Ticket Bins

Pages