Skip to content

Commit 3d3a146

Browse files
committed
make it possible to mixin into plain object
1 parent a33bdc5 commit 3d3a146

File tree

3 files changed

+16
-3
lines changed

3 files changed

+16
-3
lines changed

microevent-debug.js

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -37,7 +37,11 @@ MicroEvent.prototype = {
3737
MicroEvent.mixin = function(destObject){
3838
var props = ['bind', 'unbind', 'trigger'];
3939
for(var i = 0; i < props.length; i ++){
40-
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
40+
if( typeof destObject === 'function' ){
41+
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
42+
}else{
43+
destObject[props[i]] = MicroEvent.prototype[props[i]];
44+
}
4145
}
4246
}
4347

microevent.js

100644100755
Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -40,7 +40,11 @@ MicroEvent.prototype = {
4040
MicroEvent.mixin = function(destObject){
4141
var props = ['bind', 'unbind', 'trigger'];
4242
for(var i = 0; i < props.length; i ++){
43-
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
43+
if( typeof destObject === 'function' ){
44+
destObject.prototype[props[i]] = MicroEvent.prototype[props[i]];
45+
}else{
46+
destObject[props[i]] = MicroEvent.prototype[props[i]];
47+
}
4448
}
4549
}
4650

tests/bad.js

100644100755
Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,4 +9,9 @@ console.log("You should see 'f got blerg yes' and nothing more:");
99
console.log("")
1010

1111
f.trigger("blerg", "yes")
12-
b.trigger("blerg", "no")
12+
b.trigger("blerg", "no")
13+
14+
c = {}
15+
MicroEvent.mixin(c)
16+
c.bind('foo',function(bar){console.log(bar)})
17+
c.trigger('foo','bar')

0 commit comments

Comments
 (0)