Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fcts needs to be on instances, not prototype #1

Open
isaacs opened this issue Mar 23, 2011 · 2 comments
Open

fcts needs to be on instances, not prototype #1

isaacs opened this issue Mar 23, 2011 · 2 comments

Comments

@isaacs
Copy link

isaacs commented Mar 23, 2011

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.

@jeromeetienne
Copy link
Owner

49e7a77#diff-2

it should fix it, what do you think ?

On Wed, Mar 23, 2011 at 4:26 PM, isaacs <
[email protected]>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

@isaacs
Copy link
Author

isaacs commented Mar 23, 2011

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
[email protected]
wrote:

49e7a77#diff-2

it should fix it, what do you think ?

On Wed, Mar 23, 2011 at 4:26 PM, isaacs <
[email protected]>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)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants