English 中文(简体)
Javascript - “这”是空洞的
原标题:Javascript - "this" is empty

我试图用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 , []]]);
最佳回答

问题是你如何确定你的挫折。 它后来称它失去背景。 您要么必须设立封闭系统,要么对<条码>规定适当的约束。 结束:

var self = this;
occ[acts[i][0]](acts[i][1], this.client, function() { self.actionExecuted(); });

须遵守<条码>。

occ[acts[i][0]](acts[i][1], this.client, this.actionExecuted.bind(this));

两人都应工作。

问题回答

暂无回答




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签