Ian Bicking: the old part of his blog

Prototype and object prototype comment 000

I did see that. In this case I was just trying to reform Prototype, since I'd already started using it. I remember trying this:

def extend(ob1, ob2) {
    for (property in ob2) {
        if (typeof ob2[property] == 'function') {
            ob1[property] = ob2[property].bind(ob1);
        } else {
            ob1[property] = ob2[property];
        }
    }
    return ob1;
}

And it didn't work. Prototype's Function.prototype.bind() is, I assume, like MochiKit's bind(). I don't know quite why it didn't work -- maybe because by binding to a specific object you defeat further inheritance.

Comment on Re: Prototype.js and Object.prototype
by Ian Bicking

Comments:

You do defeat further inheritance like that.. however, in theory, you should be able to do it like this (which is one of the things I'm considering for the object model):

function isBoundFunction(func) {
    return (typeof(func.im_func) == 'function');
}

function bind(func, self) {
    var im_func = null;
    if (isBoundFunction(func)) {
        im_func = func.im_func;
    } else {
        im_func = func;
    }
    func = function () {
        return func.im_func.apply(func.im_self, arguments);
    }
    func.im_func = im_func;
    func.im_self = self;
}
# Bob Ippolito

With return func; at the end, of course.

# Bob Ippolito

Ok, just tested it.. it works in practice. Check the new implementation in svn (which is very similar to this, but it has tests and stuff).

# Bob Ippolito