English 中文(简体)
Browser javascriptenergy
原标题:Theoretical question about browser javascript engines

我怀疑这一点是可能的,我确信,在生产环境中这样做将是一个令人印象深刻的坏想法。 这只是这些假设的“I-wonder-if-I-could. ......”。

我很想知道,是否可以修改或扩大浏览器 Java式发动机在操作时间上如何使守则符合。 例如,如果我试图在 Java文中使用C#风格 lambda syntax的话:

var x = myJsObjCollection.Where(a=>a.ID == 2);

否 我修改了文字的教义,拦截了Mlambda的法典,并 myself了自己?

最佳回答

我对此表示怀疑。

捆绑和执行java字母的发动机位于客户浏览器上,因此不能通过任何网站加以修改或改变(我希望)。

也许,你可以使用 j印支持的类型和辛塔克斯来描述lam语的表述,然后拥有自己的javascript的图书馆,将其扩大到有效的javascript。

然而,这并不有用,因为 j印功能已经是多余的。 你在有效的联合材料中的法典将像同等的排位代表一样:

var x = myJsObjCollection.Where(function() { if (this.ID == 2) return this; });

没有什么工作要做。

<>Update>

还可以采取另外两个步骤:

function lambda(vName, comparison)
{
    var exp = new RegExp("\b" + vName + "\.", "g");
    comparison = comparison.replace(exp, "arg.");
    return function(arg) {
        var result;
        eval("result = " + comparison + ";");
        return result;
    };
}

嗣后: 在职能方面,可考虑:

Array.prototype.Where = function(lambdaFunc) {
    var matches = [];    
    for (var i in this)
    {
        if (lambdaFunc(this[i]))
            matches[matches.length] = this[i]
    }
    return matches;
};

你们可以说:

var x = myJsObjCollection.Where(lambda("a", "a.ID == 2"));

http://jsbin.com/ifu/2/edit"rel=“nofollow noretinger”http://jsbin.com/ifu/2/edit

问题回答

Java无法直接做到这一点。 你们最接近的是写上你自己的<代码>eval。 哪类职能可以解释你想要的哪一种规范。

或者,拿到V8 Java发动机代号,对此做了一些改动,看看你是否能够在 Chrome中加以实施:





相关问题
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.

热门标签