zepheira/exhibit3 — Issue #34: Migrate to Object.create
Author: zepheiryan
Created: 2012-01-10 07:55:11+00:00
State: open
Labels: Feature

Much of Exhibit was written at a time where imitating classical inheritance patterns was state of the art. Recent developments encourage Javascript's native prototypal inheritance pattern instead, to which end most modern engines now implement `Object.create`:

```javascript
var TrackedComponent = {
"getID": function() { return this._id; },
"setID": function() { this._id = this.getRegistryKey() + "-" + this._type; },
"getRegistryKey": function() { return this._registryKey }
};

var View = Object.create(TrackedComponent, {
"_registryKey": {
"value": "view",
"enumerable": true,
"writable": false,
"configurable": false
}
});

View.create = function() {
var view = Object.create(this);
view.setID();
return view;
};

var TileView = Object.create(View, {
"_type": {
"value": "tile",
"enumerable": true
}
});

var tv = TileView.create();
tv.getID(); // "view-tile"
```

Or something along those lines. Working with the language's native design limits instead of imposing a different paradigm on top should ultimately make it easier to abstract and deal with. There are presently notable performance penalties when using `Object.create`, so watching enhancements in this arena would help indicate when to start making the move.