Javascript static method intheritance
Posted
by
Matteo Pagliazzi
on Stack Overflow
See other posts from Stack Overflow
or by Matteo Pagliazzi
Published on 2012-06-19T08:57:57Z
Indexed on
2012/06/19
9:16 UTC
Read the original article
Hit count: 318
I want to create a javascript class/object that allow me to have various method:
Model class
Model.all()
» static methodModel.find()
» static methodModel delete()
» instance methodModel save()
» instance methodModel.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?
© Stack Overflow or respective owner