在findQuery
Ember 本地存储适配器的功能中,我对包含"[Object RegExp]"
. 这是什么意思?
if (Object.prototype.toString.call(test) == '[object RegExp]') {
push = test.test(record[property]);
} else {
push = record[property] === test;
}
[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) );