Skip to content

Instantly share code, notes, and snippets.

@varmil
Last active August 9, 2016 13:56
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 varmil/3d515c3725ddb7945c8b to your computer and use it in GitHub Desktop.
Save varmil/3d515c3725ddb7945c8b to your computer and use it in GitHub Desktop.
【javascript】やさしいクラスの作り方 ref: http://qiita.com/varmil/items/99fd6f2a886fdde4b7fa
// constructor
var hoge = function(arg) {
this.x = 5;
this.y = 10;
this.z = arg;
};
// メソッド
hoge.prototype = {
f1: function() {
return true;
},
f2: function() {
return false;
}
};
var instance = new hoge(1);
// hoge {x: 5, y: 10, z: 1, f1: function, f2: function}
var hoge = (function() {
var FOOFOO = 777; // クラス内定数
// constructor
var hoge = function(arg) {
this.x = 5;
this.y = 10;
this.z = arg;
};
var p = hoge.prototype;
p.f1 = function() {
return true;
};
p.f2 = function() {
return false;
};
return hoge;
})();
var instance = new hoge(1);
// hoge {x: 5, y: 10, z: 1, f1: function, f2: function}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment