我试图用Node.js书写我的网络应用服务器。 以下法典摘录是为了模拟局势。 问题是,申请在试图进入时坠毁。 行动概述 该财产。 此处没有界定行动(这={}在范围之内),甚至在“施工人”(请求功能本身)中加以界定。 如何从其他“方法”中获取财产?
var occ = {
exampleAction: function(args, cl, cb)
{
// ...
cb( exampleAction , [ some , results ]);
},
respond: function()
{
console.log( Successfully handled actions. );
}
};
Request = function(cl, acts)
{
this.client = cl;
this.actions = [];
this.responses = [];
// distribute actions
for (var i in acts)
{
if (acts[i][1].error == undefined)
{
this.actions.push(acts[i]);
occ[acts[i][0]](acts[i][1], this.client, this.actionExecuted);
}
else
// such an action already containing error is already handled,
// so let s pass it directly to the responses
this.responses.push(acts[i]);
}
}
Request.prototype.checkExecutionStatus = function()
{
// if all actions are handled, send data to the client
if (this.actions == [])
occ.respond(client, data, stat, this);
};
Request.prototype.actionExecuted = function(action, results)
{
// remove action from this.actions
for (var i = 0; i < this.actions.length; ++i)
if (this.actions[i][0] == action)
this.actions.splice(i, 1);
// and move it to responses
this.responses.push([action, results]);
this.checkExecutionStatus();
};
occ.Request = Request;
new occ.Request({}, [[ exampleAction , []]]);