I have this following scenarios. I am defining a new class C
and export it as a node
module. I wonder what the differences are between using a plain function (method 1
) vs. using a prototype method (method 2
).
It seems there is no global namespace pollution issue (since it is inside a module) for the helper with method 1
, but method 2
actually can expose some internal stuff (here the helper
method) to outside through prototypal inheritance.
Any other differences (performance, etc.)? Which one should I use normally?
C.prototype.func=function(){
// need to call helper, use either
// helper();
// or
// this.helper();
}
function helper(){// method 1
}
C.prototype.helper=function(){// method 2
}
module.exports = C;