以下のコードで少し混乱しています。この方法で js でクラスを作成できますか?
module.exports = function testname(paramas){
testname.test = function(req, res){
//some code here
}
return testname;
}
関数名.test の代わりに this.test を使うべきではありませんか?
以下のコードで少し混乱しています。この方法で js でクラスを作成できますか?
module.exports = function testname(paramas){
testname.test = function(req, res){
//some code here
}
return testname;
}
関数名.test の代わりに this.test を使うべきではありませんか?
ClassName.methodname
静的メンバーをthis.methodname
作成し、インスタンス メンバーを作成します
function MyClass () {
this.fn = function () {
// instance member function
}
}
MyClass.anotherFn = function () {
// Static member function
}
作成時にクラス オブジェクト内にカプセル化する必要のある変数を作成する場合は、 を使用しますthis.var
。
ただし、同じクラスのすべてのインスタンス間でデータ メンバーを共有する場合は、次を使用します。ClassName.var