jashkenas/backbone — pull request #3085 by nhunzaker (2014-03-20 23:16:00+00:00)
Title: Proposal: View.prototype._createElement to allow for overrideable DOM element creation

Fantastic work happened in #3003, I'm amazed out how quickly you can [extend Backbone to work with node](https://gist.github.com/nhunzaker/9676031)

However I had a hard time finding any discussion of adding the ability to directly change how the element associated with a view is actually produced. Right now this is a `document.create` call in `_ensureElement`

It seems like being able to override this specific behavior would be particularly useful for working with libraries such as [cheerio](http://matthewmueller.github.io/cheerio/). Making it easier to just change the _idea_ of a DOM element, leaving `_ensureElement` otherwise intact.

Of course, it isn't terribly difficult to just do something like:

```javascript
Backbone.View.prototype._ensureElement = function() {
if (!this.el) {
var attrs = _.extend({}, _.result(this, 'attributes'));
if (this.id) attrs.id = _.result(this, 'id');
if (this.className) attrs['class'] = _.result(this, 'className');

this.setElement(cheerio.load('<' + _.result(this, 'tagName') + '>'));

this._setAttributes(attrs);
} else {
this.setElement(_.result(this, 'el'));
}
};
```

However I think being able to easily slice out that one line would be pretty neat.