JS | Inheritance

by Zoltan Boros

HTML

<pre id="out"></pre>

JavaScript

var out = document.getElementById("out");

function print(text)
{
	out.innerHTML += text + "\n";
}

/** Alternative/shim of Object.create() */
function createObject(proto)
{
	function F() {}
    F.prototype = proto;
    return new F();
}

function AbstractEditor(text)
{
	this.text = text;
}

AbstractEditor.prototype.func1 = function() { print("AbstractEditor.func1() | text: " + this.text); }

function Editor(text)
{
	AbstractEditor.call(this, text);
}

Editor.prototype = createObject(AbstractEditor.prototype);
Editor.prototype.constructor = Editor;
print(Editor.prototype.constructor);

var editor1 = new Editor("editor1");
editor1.func1();