语法高亮,滚动条美化,设置页面调整

This commit is contained in:
fofolee
2019-04-19 02:41:09 +08:00
parent 1e8f76c000
commit 359d29ee0b
1590 changed files with 12328 additions and 11441 deletions

View File

@@ -1,7 +1,7 @@
<article id="wikiArticle">
<div></div>
<h2 id="信息">信息</h2>
<pre class="syntaxbox">TypeError: "x" is not a constructor
<pre><code class="language-javascript">TypeError: "x" is not a constructor
TypeError: Math is not a constructor
TypeError: JSON is not a constructor
@@ -10,7 +10,7 @@ TypeError: Reflect is not a constructor
TypeError: Intl is not a constructor
TypeError: SIMD is not a constructor
TypeError: Atomics is not a constructor
</pre>
</code></pre>
<h2 id="错误类型">错误类型</h2>
<p><a href="Reference/Global_Objects/TypeError" title="TypeError类型错误 对象用来表示值的类型非预期类型时发生的错误。"><code>TypeError</code></a></p>
<h2 id="哪里出错了">哪里出错了?</h2>
@@ -19,7 +19,7 @@ TypeError: Atomics is not a constructor
<p><a href="Reference/Statements/function*">Generator functions</a> 也不能作为构造器来使用。</p>
<h2 id="示例">示例</h2>
<h3 id="无效的">无效的</h3>
<pre class="brush: js example-bad">var Car = 1;
<pre><code class="language-js example-bad">var Car = 1;
new Car();
// TypeError: Car is not a constructor
@@ -32,30 +32,30 @@ new Symbol();
function* f() {};
var obj = new f;
// TypeError: f is not a constructor
</pre>
</code></pre>
<h3 id="一个构造器">一个构造器</h3>
<p>假设你想为汽车创建一个对象类型。 你希望此类型的对象被称为 <code>car</code>并且您希望它具有makemodel 和 year 属性。 为此,你编写以下函数:</p>
<pre class="brush: js">function Car(make, model, year) {
<pre><code class="language-javascript">function Car(make, model, year) {
this.make = make;
this.model = model;
this.year = year;
}
</pre>
</code></pre>
<p>现在你可以创建一个名为 <code>mycar</code> 的对象,如下所示:</p>
<pre class="brush: js">var mycar = new Car("Eagle", "Talon TSi", 1993);</pre>
<pre><code class="language-javascript">var mycar = new Car("Eagle", "Talon TSi", 1993);</code></pre>
<h3 id="关于_Promises">关于 Promises </h3>
<p>当返回了一个 immediately-resolved 或者 immediately-rejected Promise 的时候,你根本不需要去创建、操作一个新的 Promise 对象。</p>
<p>这是不合法的(<a href="/en-US/docs/Mozilla/JavaScript_code_modules/Promise.jsm/Promise#Constructor">Promise constructor</a> 被错误的调用了)且会抛出一个 错误 <code>TypeError: this is not a constructor</code> exception:</p>
<pre class="brush: js example-bad">return new Promise.resolve(true);
</pre>
<pre><code class="language-js example-bad">return new Promise.resolve(true);
</code></pre>
<p>使用<a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/resolve"> Promise.resolve()</a> 或者 <a href="/en-US/docs/Web/JavaScript/Reference/Global_Objects/Promise/reject">Promise.reject()</a> 静态方法来代替:</p>
<pre class="brush: js">// 这是合法的,但是没必要这么长:
<pre><code class="language-javascript">// 这是合法的,但是没必要这么长:
return new Promise((resolve, reject) =&gt; { resolve(true); })
// 用静态方法来代替:
return Promise.resolve(true);
return Promise.reject(false);
</pre>
</code></pre>
<h2 id="相关链接">相关链接</h2>
<ul>
<li><a class="glossaryLink" href="/en-US/docs/Glossary/constructor" title="constructor: A constructor belongs to a particular class object that is instantiated. The constructor initializes this object and can provide access to its private information. The concept of a constructor can be applied to most object-oriented programming languages. Essentially, a constructor in JavaScript is usually declared at the instance of a class.">constructor</a></li>