I am a bit confused with the code below, can we create class in js this way?
module.exports = function testname(paramas){
testname.test = function(req, res){
//some code here
}
return testname;
}
should not we use this.test instead of function name.test?
ClassName.methodname creates static members, while this.methodname creates instance members
function MyClass () {
this.fn = function () {
// instance member function
}
}
MyClass.anotherFn = function () {
// Static member function
}
If you want to create some variables which should be encapsulated within the class objects when you create them, use this.var.
However, if you want a data member to be shared among all the instances of the same class then use ClassName.var