
if (typeof Object.beget !== 'function') {
    Object.beget = function(o) {
        var F = function() {};
        F.prototype = o;
        return new F();
    }
}

Function.prototype.method = function (name, func) {
    this.prototype[name] = func;
    return this;
};


Function.method('new', function() {
    // creating new object that inherits from constructor's prototype
    var that = Object.beget(this.prototype);
    // invoke the constructor, binding -this- to new object
    var other = this.apply(that, arguments);
    // if its return value isn't an object substitute the new object
    return (typeof other === 'object' && other) || that;
});

Function.method('inherits', function(Parent) {
    this.prototype = new Parent();
    return this;
});

Function.method('bind', function(that) {
    var method = this;
    var slice = Array.prototype.slice;
    var args = slice.apply(arguments, [1]);
    return function() {
        return method.apply(that, args.concat(slice.apply(arguments,
            [0])));
    };
});

// as typeof is broken in Javascript, trying to get type from the constructor
Object.prototype.typeName = function() {
    return typeof(this) === 'object' ? this.constructor.toString().split(/[\s\(]/)[1] : typeof(this);
};

