// Is the given value a regular expression?
_.isRegExp = function(obj) {
return !!(obj && obj.test && obj.exec && (obj.ignoreCase || obj.ignoreCase === false));
};
alert( Object.prototype.toString.call( t ) ); // [object RegExp]
这是规范中提到的获取对象类的方法。
来自 ECMAScript 5,章节8.6.2对象内部属性和方法:
[[ Class ]]内部属性的值由此规范为每种内置对象定义。宿主对象的[[ Class ]]内部属性的值可以是除 “参数”、“数组”、“布尔”、“日期”、“错误”、“函数”、“ JSON”、“数学”、“数字”、“对象”、“正则表达式”和“字符串”之外的任何 String 值。[[ Class ]]内部属性的值在内部用于区分不同类型的对象。注意,除了通过 Object.Prototype.toString (参见15.2.4.2)之外,这个规范没有为程序提供任何访问该值的方法。
/^\/.*\/$/.test(/hi/) /* test regexp literal via regexp literal */
/^\/.*\/$/.test(RegExp("hi") ) /* test RegExp constructor via regexp literal */
RegExp("^/" + ".*" + "/$").test(/hi/) /* test regexp literal via RegExp constructor */
RegExp("^/" + ".*" + "/$").test(RegExp("hi") ) /* test RegExp constructor via RegExp constructor */
delete RegExp("hi").source /* test via deletion of the source property */
delete /hi/.global /* test via deletion of the global property */
delete /hi/.ignoreCase /* test via deletion of the ignoreCase property */
delete RegExp("hi").multiline /* test via deletion of the multiline property */
delete RegExp("hi").lastIndex /* test via deletion of the lastIndex property */