Last active
August 9, 2016 13:56
-
-
Save varmil/3d515c3725ddb7945c8b to your computer and use it in GitHub Desktop.
【javascript】やさしいクラスの作り方 ref: http://qiita.com/varmil/items/99fd6f2a886fdde4b7fa
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
// 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} |
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 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