1

findQueryEmber 本地存储适配器的功能中,我包含"[Object RegExp]". 这是什么意思?

    if (Object.prototype.toString.call(test) == '[object RegExp]') {
      push = test.test(record[property]);
    } else {
      push = record[property] === test;
    }
4

1 回答 1

2

[Object RegExp] is the string representation (toString()) of a regular expression object in Javascript.

That part of the code checks if the query is a regular expression. If so, it runs the expression object's test() on the property, otherwise does a strict === comparison.

Try running this in a console:

var test = /a.*?nice regex/;
var string = "Is this a very nice regex?";
console.log( Object.prototype.toString.call(test) );
console.log( test.test(string) );
于 2013-08-15T23:33:17.430 回答