Created
October 16, 2012 14:55
-
-
Save edom18/3899789 to your computer and use it in GitHub Desktop.
JSで継承をする仕組み。this._super() だけで親クラスのコンストラクタを呼びたい、ってことで作成。若干キモいけどいちおうは動く・・けど、もっとスマートにできないものか・・。
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(function (win, doc, exports) { | |
'use strict'; | |
/** | |
* クラス継承用関数 | |
* child ... 派生クラスを指定 | |
* _super ... 基底クラスを指定 | |
*/ | |
function extend(child, _super) { | |
function ctor() { this.constructor = child; } | |
ctor.prototype = _super.prototype; | |
child.prototype = new ctor(); | |
child.prototype._superclass = _super; | |
child.prototype._super = function () { | |
this._prevctor = (this._prevctor) ? this._prevctor.prototype._superclass : _super; | |
this._prevctor.apply(this, arguments); | |
}; | |
} | |
/*! ------------------------------------------------------------------------ | |
内部で定義したクラスを外部から参照できるようにExport | |
---------------------------------------------------------------------------- */ | |
exports.extend = extend; | |
}(window, document, window)); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment