Search code examples
javascriptprototype

Prototype calling constructor run


Here, i want run a function in same page

const USER = function () {},
ACTION = function () {};
USER.prototype.set = function(data){
   db.user.insert(data);
};
USER.prototype.get = function(id,callback){
   db.get(id,function(rs){
    **ACTION.set(data); // how can i call here**
    callback(rs);
   });  
};
ACTION.prototype.set = function(data){
    db.action.insert(data)
}

module.exports = { USER : new USER() }

is it possible? USER.get function calling ACTION.set function?


Solution

  • Yes, It is possible. But, first you need to instance the class ACTION. let action = new ACTION() action.set(value_here)