Skip to content


Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
JavaScript object inheritance sugar: Easy extension, mixins, super methods, proxies
tag: 1.0.2

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.

Uberproto is a simple base object that adds some sugar to ECMAScript 5 style object inheritance in JavaScript.

Here is what it can do in a nutshell:

  • Easily extend objects
  • Initialization methods
  • Super methods
  • Mixins
  • Method proxies

With a small footprint (about 1Kb minified) and an easy to handle API of just four methods it also doesn't add a lot of baggage to your JavaScript application.


UberProto can be used as a CommonJS AMD module (e.g. with RequireJS), NodeJS or directly in the browser. If no module loader is available, the global variable Proto will be defined after you include the script.

Using AMD (e.g. RequireJS)

Make sure proto.js is in the right folder and then just define a module like this:

define(['proto'], function(Proto) {
    // Source goes here

In the browser

Download proto.min.js (1Kb minified) and include it as a script:

<script type="text/javascript" src="proto.min.js"></script>

Now Proto is available as a global vairable.

With NodeJS

After installing the package using NPM

npm install uberproto

just require it like any other module:

var Proto = require('uberproto');

Creating objects


You can extend any UberProto object by using extend to create a new object that inherits from the current one. Internally Object.create is being used (the library provides a polyfill for browsers that don't support Object.create) and the prototype is set to the object that you are extending. If defined, the init method will be used as the constructor. That way you can define a simple Person object (which will be reused throughout the next paragraphs):

var Person = Proto.extend({
    init : function(name) { = name;

    fullName : function() {

You can also define a plain object and pass it to UberProto object methods:

var PersonObject = {
    init : function(name) { = name;

    fullName : function() {

Play around with the examples in this JSFiddle.


You can create a new instance by calling create. This will create a new object and call the init method, if defined:

var dave = Person.create('Dave');
console.log(; // -> 'Dave'
console.log(dave.fullName()); // -> 'Dave'

If you are using init already for something else you can also set the __init property to the method name of your intialization method:

var MyPerson = Proto.extend({
    __init : 'construct',

    construct : function(name) { = name;

For calling the constructor on a plain object, call create on an UberProto object:

var john =, 'John');
console.log(john.fullName()); // -> 'John'

Overwriting create is great if you want to customize the way new objects are being instantiated.

Super methods

In each method this._super refers to the method being overwritten, if there is one. For our Person object, for example, it would be a lot better if it also had a last name:

var BetterPerson = Person.extend({
    init : function(name, lastname) {
        // If you want to pass all original arguments to the
        // _super method just use apply:
        // this._super.apply(this, arguments);

        this.lastname = lastname;

    fullName : function() {
        return this._super() + ' ' + this.lastname;

var dave = BetterPerson.create('Dave', 'Doe');
console.log(; // -> 'Dave'
console.log(dave.lastname); // -> 'Doe'
console.log(dave.fullName()); // -> 'Dave Doe'

You can also extend a plain object if you don't want to inherit from an UberProto object:

var BetterPersonObject = Proto.extend({
    init : function(name, lastname) {
        this.lastname = lastname;

    fullName : function() {
        return this._super() + ' ' + this.lastname;
}, PersonObject); // Pass the plain object as the second parameter


Mixins add functionality to an existing object. Mixins can also access their super methods using this._super. This will either refer the overwritten method on the object itself or the one on the prototype:

    init : function()
        this._super.apply(this, arguments);
        this.can_sing = true;

    sing : function()
        return 'Laaaa';

var dude = Person.create('Dude');
console.log(dude.sing()); // -> 'Laaaa'
console.log(dude.can_sing); // -> true

Actual instances can be mixed in just the same:

var operaSinger = Person.create('Pavarotti');
    sing : function()
        return this._super() + ' Laalaaa!';

console.log(operaSinger.sing()); // -> 'Laaaa Laalaaa!

And you can also mix into plain objects e.g. overwriting the constructor of PersonObject:

    fullName : function() {
        return 'My name is: ' + this._super();
}, PersonObject);

// Create a plain object without calling the constructor
var instance = Object.create(PersonObject); = 'Dude';
console.log(instance.fullName()); // 'My name is: Dude'

Method proxy

You can create proxy callbacks, that make sure that this will always point to the right object:

var callback = operaSinger.proxy('fullName');
console.log(callback()); // -> 'Pavarotti'

And of course proxy methods of plain objects:

var cb = Proto.proxy('fullName', PersonObject);



  • Added __init property to allow constructor functions to be named other than init. Fixes issue #1


  • API now usable with plain objects like Proto.mixin({}, PlainObject)


  • Initial stable release
Something went wrong with that request. Please try again.