English 中文(简体)
为什么这种 Q试失败?
原标题:Why does this QUnit RegExp test fail?

我与QUnit坐在一起,我 one了一件事。

我对 Chrome进行了这一简单检验:

deepEqual(new RegExp(), /(?:)/);

我假定它将通过,因为:new RegExp( 回归代码>/(?:)/ in the Development Console。 <代码>new RegExp() ==/(?)/ for RegExps,但toString(功能既是回报又是are<>。

我认为,字面/非物字句会起作用,但是,由于这一试样,情况并非如此:

deepEqual(new RegExp(" "), / /);

因此,在以下试验中,第一个试验失败:

test("test", function() {
    deepEqual(new RegExp(), /(?:)/); // fail
    deepEqual(new RegExp(" "), / /); // pass
    equal(new RegExp().toString(), /(?:)/.toString()); // pass
});

Therefore, could someone point me in the right direction as to why the first test fails please?

最佳回答

www.un.org/Depts/DGACM/index_spanish.htm 简短回答: 。 在字面上,它有<代码>(?)/,而就物体而言,它只是空洞。 当您填写/new RegExp(>时,source property is the same (两者都是用一个空间-character做的说明)。

。 如果你看着Qunit的消息来源,你看着这个法典的范畴:

"regexp": function (b, a) {
    return QUnit.objectType(b) === "regexp" &&
        a.source === b.source && // the regex itself
        a.global === b.global && // and its modifers (gmi) ...
        a.ignoreCase === b.ignoreCase &&
        a.multiline === b.multiline;
};

你们可以看看,如何使用本法典来区分源参数(它只是将每一浮游动物的特性加以输出,并检验其平等):

function eq(x, y) {
   console.log("x.source:", " " + x.source + " ", "y.source:", " " + y.source + " ", "===:", x.source === y.source);
   console.log("x.global:", x.global, "y.global:", y.global, "===:", x.global === y.global);
   console.log("x.ignoreCase:", x.ignoreCase, "y.ignoreCase:", y.ignoreCase, "===:", x.ignoreCase === y.ignoreCase);
   console.log("x.multiline:", x.multiline, "y.multiline:", y.multiline, "===:", x.multiline === y.multiline);
}

When you call this with eq(/(?:)/, new RegExp());, you get:

x.source:  (?:)  y.source:    ===: false
x.global: false y.global: false ===: true
x.ignoreCase: false y.ignoreCase: false ===: true
x.multiline: false y.multiline: false ===: true

当你打电话到<条码>以下(///,新编号(“”)时,请上

x.source:     y.source:     ===: true
x.global: false y.global: false ===: true
x.ignoreCase: false y.ignoreCase: false ===: true
x.multiline: false y.multiline: false ===: true
问题回答

暂无回答




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