mirror of
https://github.com/fofolee/uTools-Manuals.git
synced 2026-02-27 01:21:38 +08:00
语法高亮,滚动条美化,设置页面调整
This commit is contained in:
@@ -2,16 +2,16 @@
|
||||
<div></div>
|
||||
<p><strong>类表达式</strong>是用来定义类的一种语法。和<a href="/zh-CN /docs/Web/JavaScript/Reference/Operators/function">函数表达式</a>相同的一点是,类表达式可以是命名也可以是匿名的。如果是命名类表达式,这个名字只能在类体内部才能访问到。JavaScript 的类也是基于原型继承的。</p>
|
||||
<h2 id="语法">语法</h2>
|
||||
<pre class="syntaxbox">const MyClass = class <em>[className]</em> [extends] {
|
||||
<pre><code class="language-javascript">const MyClass = class <em>[className]</em> [extends] {
|
||||
// class body
|
||||
};</pre>
|
||||
};</code></pre>
|
||||
<h2 id="描述">描述</h2>
|
||||
<p>类表达式的语法和<a href="/zh-CN /docs/Web/JavaScript/Reference/Statements/class">类语句</a>的语法很类似,只是在类表达式中,你可以省略掉类名,而类语句中不能。</p>
|
||||
<p>和类声明一样,类表达式中的代码也是强制<a href="/zh-CN /docs/Web/JavaScript/Reference/Strict_mode">严格模式</a>的。</p>
|
||||
<h2 id="示例">示例</h2>
|
||||
<h3 id="使用类表达式">使用类表达式</h3>
|
||||
<p>下面的代码使用类表达式语法创建了一个匿名类,然后赋值给变量 Foo。</p>
|
||||
<pre class="brush: js">let Foo = class {
|
||||
<pre><code class="language-javascript">let Foo = class {
|
||||
constructor() {}
|
||||
bar() {
|
||||
return "Hello World!";
|
||||
@@ -21,10 +21,10 @@
|
||||
let instance = new Foo();
|
||||
instance.bar();
|
||||
// "Hello World!"
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h3 id="命名类表达式">命名类表达式</h3>
|
||||
<p>如果你想在类体内部也能引用这个类本身,那么你就可以使用命名类表达式,并且这个类名只能在类体内部访问。</p>
|
||||
<pre class="brush: js">const Foo = class NamedFoo {
|
||||
<pre><code class="language-javascript">const Foo = class NamedFoo {
|
||||
constructor() {}
|
||||
whoIsThere() {
|
||||
return NamedFoo.name;
|
||||
@@ -42,7 +42,7 @@ NamedFoo.name;
|
||||
Foo.name;
|
||||
// "NamedFoo"
|
||||
|
||||
</pre>
|
||||
</code></pre>
|
||||
<h2 id="规范">规范</h2>
|
||||
<table>
|
||||
<tbody>
|
||||
|
||||
Reference in New Issue
Block a user