Javascript static method intheritance
- by Matteo Pagliazzi
I want to create a javascript class/object that allow me to have various method:
Model class
Model.all() » static method
Model.find() » static method
Model delete() » instance method
Model save() » instance method
Model.create() » static that returns a new Model instance
For static method I can define them using:
Model.staticMethod(){ method }
while for instance method is better to use:
function Model(){
this.instanceMethod = function(){}
}
and then create a new instance
or using prototype?
var m = function Model(){
}
m.prototype.method() = function(){
}
Now let's say that I want to create a new class based on Model, how to inherit not only its prototypes but also its static methods?