La herencia de JavaScript adecuada para este caso específico

I'm dealing with a database table object that will contains all table info like fields name, table name, ecc.

That object have a method spawnRecord that will return a void record object that inherits from the table object.

The record object represent a single record of the db and have methods like load, update and insert. This allows to load a db record in the memory, to modify it and to update the same in the db.

Since I need to create many table objects and many record objects what is the most easy and clean way to do this?

I read the Douglas Crockford prototype approach, the classical approach, I tried to implement it but I get a lot of confusion and a code difficult to read.

preguntado el 09 de marzo de 12 a las 16:03

On general principles, I advise embracing Javascript as Javascript and go for the prototype approach. --- If you show some of your code attempts, someone might help you out with getting them working. -

3 Respuestas

From what you're describing, it sounds like you need an ORM (object-relational mapping) tool for JavaScript. Maybe something like jazzrecord or activejs Te ayudará.

respondido 09 mar '12, 16:03

Puede usar el jQuery.klass. It supports multiple levels of inheritance.

respondido 09 mar '12, 16:03

You can do this John Resig's way - a tiny script does many things -

http://ejohn.org/blog/simple-javascript-inheritance/

1) multi level inheritance
2) 'instanceof' works as it should
3) call super class method from a subclass using 'super'
4) provide a constructor etc.

respondido 09 mar '12, 16:03

No es la respuesta que estás buscando? Examinar otras preguntas etiquetadas or haz tu propia pregunta.