Skip to content

0.2.7 usage extend

Ivan S Glazunov edited this page Feb 20, 2015 · 2 revisions

Extend?

Prototype.extend(injector?: TInjector) => Function;

All elements are extensions of Prototype.

Each element has the option .constructor, which you can override when inheritance. It contains the build process makes the element element.

Each element has the option .returner, which specifies what will be returned by the constructor.

The extension is with the argument of the TInjector or without.

Without TInjector
var myTag = div('.myTag')().extend();
myTag()().render(console.log);
<div class="myTag"></div>
With TInjector

Here we simply disable return constructor method .content.

var injector = function() {
	var parent = this._parent;
	this.constructor = function() {
	    parent.constructor.apply(this, arguments);
	    this.append(' after');
	};
    this.returner = function() { return this; };
};
var myTag = div('.myTag')('content').extend(injector);
myTag().render(console.log);
<div class="myTag">content after</div>

Clone this wiki locally