Created
February 3, 2013 15:21
-
-
Save kazukgw/4702162 to your computer and use it in GitHub Desktop.
Class generated by CoffeeScript #js
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
//クラスの作成と継承 | |
var fuga, hoge, | |
__hasProp = {}.hasOwnProperty, | |
__extends = function(child, parent) { | |
//親のプロパティをすべて引き継ぐ | |
for (var key in parent) { | |
if (__hasProp.call(parent, key)) child[key] = parent[key]; | |
} | |
//コンストラクタ関数を定義 | |
function ctor() { | |
//ここのthisはグローバルオブジェクト? | |
// 以下でnewで呼び出されてるので | |
// new で生成された新しいオブジェクトが this | |
this.constructor = child; | |
} | |
//コンストラクタ関数のprototypeは親のprototype | |
ctor.prototype = parent.prototype; | |
//継承する子供オブジェクトはコンストラクタ関数によって初期化される。 | |
child.prototype = new ctor(); | |
//一応superで親のprototypeをたどれる。 | |
child.__super__ = parent.prototype; | |
return child; | |
}; | |
fuga = (function() { | |
function fuga() {} | |
return fuga; | |
})(); | |
hoge = (function(_super) { | |
__extends(hoge, _super); | |
function hoge() { | |
return hoge.__super__.constructor.apply(this, arguments); | |
} | |
return hoge; | |
})(fuga); | |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment