Skip to content

Instantly share code, notes, and snippets.

@kazukgw
Created February 3, 2013 15:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save kazukgw/4702162 to your computer and use it in GitHub Desktop.
Save kazukgw/4702162 to your computer and use it in GitHub Desktop.
Class generated by CoffeeScript #js
//クラスの作成と継承
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