Skip to content

Using Mixin on objects #14

Open
Open
@xeoncross

Description

@xeoncross

I'm doubt this is an issue, probably just a problem with what I'm doing but I can't get mixins to work using the default method.

MicroEvent.mixin    = function(destObject){
    var props   = ['bind', 'unbind', 'trigger'];
    for(var i = 0; i < props.length; i ++){
        destObject.prototype[props[i]]  = MicroEvent.prototype[props[i]];
    }
}

When trying with an object

var obj = {
    foo : 'bar',
     method : function() { }
};
    MicroEvent.mixin(obj);

I get can't convert undefined to object. If I change the method to this though it works:

MicroEvent.mixin2 = function(destObject)
{
    for (var k in MicroEvent.prototype)
    {
        if (MicroEvent.prototype.hasOwnProperty(k))
        {
            destObject[k] = MicroEvent.prototype[k];
        }
    }
}

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions