--- title: RegExp.prototype.toSource() slug: Web/JavaScript/Reference/Global_Objects/RegExp/toSource tags: - JavaScript - Method - Non-standard - Prototype - RegExp translation_of: Web/JavaScript/Reference/Global_Objects/RegExp/toSource ---
{{JSRef("Global_Objects", "RegExp")}}{{ Non-standard_header() }}
返回一个字符串,代表当前对象的源代码
regexObj.toSource()
toSource方法返回值如下:
RegExp对象, toSource 如下字符串:function RegExp() {
[native code]
}
RegExp实例, toSource返回代表该正则的字符串.该方法通常由JavaScript内部隐含调用,而不会明确的出现在用户代码中.