node.js - Generic JavaScript Models using Composition -
    i working on node.js application couple of javascript model this:   function role(data) {   this.data = data;   ... }  role.prototype.save = function(...) {...}  role.findbyid = function(...) {...} role.findall = function(...) {...}   all of them using same (similar) logic of functions, need different implementation saving , on. idea refactor them using kind of composition. current solution combination of using inheritance prototype functions , adapter static functions. looks this.   var _adapter = new databaseadapter(schema, table, role);  function role(data) {   model.call(this, _adapter, role._attributes)   this.data = data;   ... }  role._attributes = {   name: '' }  role.prototype.save = function(...) {...}  role.findbyid = function(...) {   _adapter.findbyid(...); }  role.findall = function(...) {   _adapter.findall(...) }   but, not happy current solution, because developers need know lot of implementation details create new model. so, hope show me better approach so...