jeromeetienne / microevent.js

event emitter microlibrary - 20lines -for node and browser

Home Page:http://notes.jetienne.com/2011/03/22/microeventjs.html

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

fcts needs to be on instances, not prototype

isaacs opened this issue · comments

Since fcts is on the prototype, and an object, it's shared by all instances of the same emitter class.

function Foo () {}
MicroEvent.mixin(Foo)
f = new Foo
b = new Foo
f.bind("blerg", function () { console.log("f got blerg") })
b.trigger("blerg")

Instead of putting fcts on the prototype, you must check for it on the object at the start of the bind/trigger/unbind functions and default it to {} if it's not set or not an object.

49e7a77#diff-2

it should fix it, what do you think ?

On Wed, Mar 23, 2011 at 4:26 PM, isaacs <
reply@reply.github.com>wrote:

Since fcts is on the prototype, and an object, it's shared by all instances
of the same emitter class.

function Foo () {}
MicroEvent.mixin(Foo)
f = new Foo
b = new Foo
f.bind("blerg", function () { console.log("f got blerg") })
b.trigger("blerg")

Instead of putting fcts on the prototype, you must check for it on the
object at the start of the bind/trigger/unbind functions and default it to
{} if it's not set or not an object.

Reply to this email directly or view it on GitHub:
#1

Yeah, that should do it.

You might want to make sure that typeof this.fcts === 'object' so
that you don't end up trying to set a property on a 7 or something.

On Wed, Mar 23, 2011 at 08:39, jeromeetienne
reply@reply.github.com
wrote:

49e7a77#diff-2

it should fix it, what do you think ?

On Wed, Mar 23, 2011 at 4:26 PM, isaacs <
reply@reply.github.com>wrote:

Since fcts is on the prototype, and an object, it's shared by all instances
of the same emitter class.

   function Foo () {}
   MicroEvent.mixin(Foo)
   f = new Foo
   b = new Foo
   f.bind("blerg", function () { console.log("f got blerg") })
   b.trigger("blerg")

Instead of putting fcts on the prototype, you must check for it on the
object at the start of the bind/trigger/unbind functions and default it to
{} if it's not set or not an object.

Reply to this email directly or view it on GitHub:
#1

Reply to this email directly or view it on GitHub:
#1 (comment)