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?
EDIT:
to avoid confusion this is more or less what I want to create:
http://activejs.org/activerecord/index.html and http://activejs.org/activerecord/ActiveRecord/Model/index.html
where I can define a new model using something like that
var User = ActiveRecord.create({
username: '',
password: '',
post_count: 0,
profile: ''
}
then create an instance
var jessica = User.create({
username: "Jessica",
password: "rabbit"
});
use instance methods like
jessica.save();
but also class methods:
User.findByUsername('Jessica');