我对下面的代码有点困惑,我们可以这样在js中创建类吗?
module.exports = function testname(paramas){
testname.test = function(req, res){
//some code here
}
return testname;
}
我们不应该使用 this.test 代替函数 name.test 吗?
我对下面的代码有点困惑,我们可以这样在js中创建类吗?
module.exports = function testname(paramas){
testname.test = function(req, res){
//some code here
}
return testname;
}
我们不应该使用 this.test 代替函数 name.test 吗?
ClassName.methodname
创建静态成员,同时this.methodname
创建实例成员
function MyClass () {
this.fn = function () {
// instance member function
}
}
MyClass.anotherFn = function () {
// Static member function
}
如果要创建一些在创建类对象时应封装在类对象中的变量,请使用this.var
.
但是,如果您希望在同一类的所有实例之间共享数据成员,则使用ClassName.var