diff options
Diffstat (limited to 'files/zh-cn/web/javascript/reference/global_objects/error/tosource')
| -rw-r--r-- | files/zh-cn/web/javascript/reference/global_objects/error/tosource/index.html | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/files/zh-cn/web/javascript/reference/global_objects/error/tosource/index.html b/files/zh-cn/web/javascript/reference/global_objects/error/tosource/index.html new file mode 100644 index 0000000000..89273b1f32 --- /dev/null +++ b/files/zh-cn/web/javascript/reference/global_objects/error/tosource/index.html @@ -0,0 +1,53 @@ +--- +title: Error.prototype.toSource() +slug: Web/JavaScript/Reference/Global_Objects/Error/toSource +translation_of: Web/JavaScript/Reference/Global_Objects/Error/toSource +--- +<div>{{JSRef}} {{non-standard_header}}</div> + +<p><code><strong>toSource()</strong></code> 方法返回可以计算出到相同错误的代码。</p> + +<h2 id="语法">语法</h2> + +<pre class="syntaxbox"><var>e</var>.toSource()</pre> + +<h3 id="返回值">返回值</h3> + +<p>一个包含错误源代码的字符串</p> + +<h2 id="描述">描述</h2> + +<p>调用一个{{jsxref("Error")}}实例的<code>toSource</code>方法(包括 <em><a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Error#Error_types">NativeErrors</a></em>)将返回包含错误源代码的字符串。 这个字符串可以被评估创建一个(大约)相等的对象。当然,包含源字符串遵循的结构{{ jsxref("Error")}} 构造函数。例如:</p> + +<pre class="brush: js">(new<em>name</em>(<em>message</em> ,<em>fileName</em>,<em>lineNumber</em>)) +</pre> + +<p>这些属性对应于错误实例的相应属性。</p> + +<div class="note"> +<p><strong>提示:</strong> 需要注意到,在创建该字符串时,<code>toSource</code>方法所使用的属性是可变的,并且可能无法准确地反映用于创建错误实例的函数或实际发生错误的文件名或行号。</p> +</div> + +<h2 id="规范">规范</h2> + +<p>不属于任何规范. 应用于 in JavaScript 1.3.</p> + +<h2 id="浏览器兼容性">浏览器兼容性</h2> + +<div> +<div> +<div class="hidden">这个页面上的兼容性表是由结构化数据生成的。如果您想对数据作出贡献,请查看https://github.com/mdn/browser-compat-data并发送一个pull请求。</div> + +<p>{{Compat("javascript.builtins.Error.toSource")}}</p> +</div> +</div> + +<h2 id="相关链接">相关链接</h2> + +<ul> + <li>{{jsxref("Error.prototype.fileName")}}</li> + <li>{{jsxref("Error.prototype.lineNumber")}}</li> + <li>{{jsxref("Error.prototype.message")}}</li> + <li>{{jsxref("Error.prototype.name")}}</li> + <li>{{jsxref("Object.prototype.toSource()")}}</li> +</ul> |
