mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-26 17:11:20 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,14 +2,14 @@
|
||||
<div></div>
|
||||
<p><strong><code>extends</code></strong>关键字用于<a href="Reference/Statements/class">类声明</a>或者<a href="Reference/Operators/class">类表达式</a>中,以创建一个类,该类是另一个类的子类。</p>
|
||||
<h2 id="语法">语法</h2>
|
||||
<pre class="syntaxbox">class ChildClass extends ParentClass { ... }</pre>
|
||||
<pre><code class="language-javascript">class ChildClass extends ParentClass { ... }</code></pre>
|
||||
<h2 id="描述">描述</h2>
|
||||
<p><code>extends</code>关键字用来创建一个普通类或者内建对象的子类。</p>
|
||||
<p><font face="Open Sans, Arial, sans-serif">继承的</font><code>.prototype</code>必须是一个<a href="Reference/Global_Objects/Object" title="Object 构造函数创建一个对象包装器。"><code>Object</code></a> 或者 <a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a>。</p>
|
||||
<h2 id="示例">示例</h2>
|
||||
<h3 id="使用_extends">使用 <code>extends</code></h3>
|
||||
<p>第一个例子是根据名为 <code style="font-style: normal;">Polygon</code> 类创建一个名为<code>Square</code>的类。这个例子是从这个<a class="external" href="https://googlechrome.github.io/samples/classes-es6/index.html" rel="noopener">在线演示</a>中提取出来的。</p>
|
||||
<pre class="brush: js">class Square extends Polygon {
|
||||
<pre><code class="language-javascript">class Square extends Polygon {
|
||||
constructor(length) {
|
||||
// Here, it calls the parent class' constructor with lengths
|
||||
// provided for the Polygon's width and height
|
||||
@@ -22,10 +22,10 @@
|
||||
get area() {
|
||||
return this.height * this.width;
|
||||
}
|
||||
}</pre>
|
||||
}</code></pre>
|
||||
<h3 id="使用_extends与内置对象">使用 <code>extends</code>与内置对象</h3>
|
||||
<p>这个示例继承了内置的<a href="Reference/Date" title="此页面仍未被本地化, 期待您的翻译!"><code>Date</code></a>对象。这个例子是从这个<a class="external" href="https://googlechrome.github.io/samples/classes-es6/index.html" rel="noopener">在线演示</a>中提取出来的。</p>
|
||||
<pre class="brush: js">class myDate extends Date {
|
||||
<pre><code class="language-javascript">class myDate extends Date {
|
||||
constructor() {
|
||||
super();
|
||||
}
|
||||
@@ -34,17 +34,17 @@
|
||||
var months = ['Jan','Feb','Mar','Apr','May','Jun','Jul','Aug','Sep','Oct','Nov','Dec'];
|
||||
return this.getDate() + "-" + months[this.getMonth()] + "-" + this.getFullYear();
|
||||
}
|
||||
}</pre>
|
||||
}</code></pre>
|
||||
<h3 id="扩展_null">扩展 <code>null</code></h3>
|
||||
<p>可以像扩展普通类一样扩展<a href="Reference/Global_Objects/null" title="值 null 特指对象的值未设置。它是 JavaScript 基本类型 之一。"><code>null</code></a>,但是新对象的原型将不会继承 <a href="Reference/Global_Objects/Object/prototype" title="Object.prototype 属性表示 Object 的原型对象。"><code>Object.prototype</code></a>。</p>
|
||||
<pre class="brush: js">class nullExtends extends null {
|
||||
<pre><code class="language-javascript">class nullExtends extends null {
|
||||
constructor() {}
|
||||
}
|
||||
|
||||
Object.getPrototypeOf(nullExtends); // Function.prototype
|
||||
Object.getPrototypeOf(nullExtends.prototype) // null
|
||||
|
||||
new nullExtends(); //ReferenceError: this is not defined</pre>
|
||||
new nullExtends(); //ReferenceError: this is not defined</code></pre>
|
||||
<h2 id="标准">标准</h2>
|
||||
<table class="standard-table">
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user