Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/447.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 原型调用构造函数运行_Javascript_Prototype - Fatal编程技术网

Javascript 原型调用构造函数运行

Javascript 原型调用构造函数运行,javascript,prototype,Javascript,Prototype,在这里,我想在同一个页面上运行一个函数 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 cal

在这里,我想在同一个页面上运行一个函数

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() }

可能吗?USER.get函数调用ACTION.set函数?

是的,这是可能的。但是,首先你需要执行集体诉讼。 让动作=新动作()
action.set(这里的值)

您可以通过newaction()调用
action.set

反而

**ACTION.set(data);
使用


您分配给
ACTION.prototype.set
,因此使用
ACTION.prototype.set(数据)
调用。但是您可能不应该使用这样的类。
var action = new ACTION();
action.set(data)