mirror of
https://github.com/gnu4cn/ts-learnings.git
synced 2025-01-28 05:10:12 +08:00
775 lines
66 KiB
HTML
775 lines
66 KiB
HTML
|
|
<!DOCTYPE HTML>
|
|
<html lang="" >
|
|
<head>
|
|
<meta charset="UTF-8">
|
|
<meta content="text/html; charset=utf-8" http-equiv="Content-Type">
|
|
<title>变量声明 · GitBook</title>
|
|
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
|
|
<meta name="description" content="">
|
|
<meta name="generator" content="GitBook 3.2.3">
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/style.css">
|
|
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-highlight/website.css">
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-search/search.css">
|
|
|
|
|
|
|
|
<link rel="stylesheet" href="gitbook/gitbook-plugin-fontsettings/website.css">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<meta name="HandheldFriendly" content="true"/>
|
|
<meta name="viewport" content="width=device-width, initial-scale=1, user-scalable=no">
|
|
<meta name="apple-mobile-web-app-capable" content="yes">
|
|
<meta name="apple-mobile-web-app-status-bar-style" content="black">
|
|
<link rel="apple-touch-icon-precomposed" sizes="152x152" href="gitbook/images/apple-touch-icon-precomposed-152.png">
|
|
<link rel="shortcut icon" href="gitbook/images/favicon.ico" type="image/x-icon">
|
|
|
|
|
|
<link rel="next" href="03_classes.html" />
|
|
|
|
|
|
<link rel="prev" href="01_basic_data_types.html" />
|
|
|
|
|
|
</head>
|
|
<body>
|
|
|
|
<div class="book">
|
|
<div class="book-summary">
|
|
|
|
|
|
<div id="book-search-input" role="search">
|
|
<input type="text" placeholder="Type to search" />
|
|
</div>
|
|
|
|
|
|
<nav role="navigation">
|
|
|
|
|
|
|
|
<ul class="summary">
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
<li class="chapter " data-level="1.1" data-path="./">
|
|
|
|
<a href="./">
|
|
|
|
|
|
Introduction
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.2" data-path="01_basic_data_types.html">
|
|
|
|
<a href="01_basic_data_types.html">
|
|
|
|
|
|
基本数据类型
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter active" data-level="1.3" data-path="02_variables_declaration.html">
|
|
|
|
<a href="02_variables_declaration.html">
|
|
|
|
|
|
变量声明
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.4" data-path="03_classes.html">
|
|
|
|
<a href="03_classes.html">
|
|
|
|
|
|
类
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.5" data-path="04_interfaces.html">
|
|
|
|
<a href="04_interfaces.html">
|
|
|
|
|
|
接口
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.6" data-path="05_functions.html">
|
|
|
|
<a href="05_functions.html">
|
|
|
|
|
|
函数
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.7" data-path="06_generics.html">
|
|
|
|
<a href="06_generics.html">
|
|
|
|
|
|
泛型
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.8" data-path="07_enums.html">
|
|
|
|
<a href="07_enums.html">
|
|
|
|
|
|
枚举
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
<li class="chapter " data-level="1.9" data-path="08_type_inference.html">
|
|
|
|
<a href="08_type_inference.html">
|
|
|
|
|
|
类型推导
|
|
|
|
</a>
|
|
|
|
|
|
|
|
</li>
|
|
|
|
|
|
|
|
|
|
<li class="divider"></li>
|
|
|
|
<li>
|
|
<a href="https://www.gitbook.com" target="blank" class="gitbook-link">
|
|
Published with GitBook
|
|
</a>
|
|
</li>
|
|
</ul>
|
|
|
|
|
|
</nav>
|
|
|
|
|
|
</div>
|
|
|
|
<div class="book-body">
|
|
|
|
<div class="body-inner">
|
|
|
|
|
|
|
|
<div class="book-header" role="navigation">
|
|
|
|
|
|
<!-- Title -->
|
|
<h1>
|
|
<i class="fa fa-circle-o-notch fa-spin"></i>
|
|
<a href="." >变量声明</a>
|
|
</h1>
|
|
</div>
|
|
|
|
|
|
|
|
|
|
<div class="page-wrapper" tabindex="-1" role="main">
|
|
<div class="page-inner">
|
|
|
|
<div id="book-search-results">
|
|
<div class="search-noresults">
|
|
|
|
<section class="normal markdown-section">
|
|
|
|
<h1 id="变量的声明,variables-declaration">变量的声明,Variables Declaration</h1>
|
|
<p><code>let</code>与<code>const</code>是较新一版JavaScript(ES6)中变量声明的方式。前一部分提到,<code>let</code>在很多方面与<code>var</code>是相似的,但<code>let</code>却可以帮助大家解决JavaScript中的一些常见问题。<code>const</code>是对<code>let</code>的一个增强,可阻止对经其修饰的变量的再次赋值。</p>
|
|
<p>因为TypeScript是JavaScript的超集(super-set),所以自然有对JavaScript所有特性的支持,<code>let</code>与<code>const</code>关键字也不例外。以下将详细讨论这些全新的声明方式,以及为何要用它们来取代<code>var</code>的原因。</p>
|
|
<p>如果你还没有发现JavaScript中使用<code>var</code>所带来的问题,那么下面的内容将唤起你的记忆。</p>
|
|
<h2 id="关于var式变量声明">关于<code>var</code>式变量声明</h2>
|
|
<p>JavaScript使用<code>var</code>关键字来声明变量,有着悠久的历史:</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
|
|
</code></pre>
|
|
<p>显而易见,这里定义出一个名为<code>a</code>的值为<code>10</code>的变量(指向某个内存单元地址)。</p>
|
|
<p>在函数内部,也可以进行变量的定义:</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">var</span> msg = <span class="hljs-string">"Hello, World!"</span>
|
|
|
|
<span class="hljs-keyword">return</span> msg;
|
|
}
|
|
</code></pre>
|
|
<p>在其它函数内部,也可以访问相同变量:</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">var</span> a = <span class="hljs-number">10</span>;
|
|
|
|
<span class="hljs-keyword">return</span> <span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span>(<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">var</span> b = a+<span class="hljs-number">1</span>;
|
|
<span class="hljs-keyword">return</span> b;
|
|
}
|
|
}
|
|
|
|
<span class="hljs-keyword">var</span> g = f();
|
|
g();
|
|
</code></pre>
|
|
<p>在上面的例子中,<code>g</code> 可以获取到函数<code>f</code>里定义的变量<code>a</code>。在<code>g</code>被调用时,它都可以访问到<code>f</code>里的变量<code>a</code>。 <em>即使<code>g</code>在<code>f</code>已经执行完毕后才被调用,其任可以访问并对<code>a</code>进行修改</em> 。</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">var</span> a = <span class="hljs-number">1</span>;
|
|
|
|
a = <span class="hljs-number">2</span>;
|
|
|
|
<span class="hljs-keyword">var</span> b = g();
|
|
|
|
a = <span class="hljs-number">3</span>;
|
|
|
|
<span class="hljs-keyword">return</span> b;
|
|
|
|
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">return</span> a;
|
|
}
|
|
}
|
|
|
|
f(); <span class="hljs-comment">// 返回的是 2</span>
|
|
</code></pre>
|
|
<h2 id="作用域规则(scope-rules)">作用域规则(Scope Rules)</h2>
|
|
<p>加入对其它严格的编程语言比较熟悉,那么对于JavaScript中<code>var</code>声明的作用域规则,将感到奇怪。比如:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">shouldInitialize: <span class="hljs-built_in">boolean</span></span>) </span>{
|
|
<span class="hljs-keyword">if</span> ( shouldInitialize ) {
|
|
<span class="hljs-keyword">var</span> x = <span class="hljs-number">10</span>;
|
|
}
|
|
|
|
<span class="hljs-keyword">return</span> x;
|
|
}
|
|
|
|
f(<span class="hljs-literal">true</span>); <span class="hljs-comment">// 返回的是 `10`</span>
|
|
f(<span class="hljs-literal">false</span>); <span class="hljs-comment">// 返回 `undefined`</span>
|
|
</code></pre>
|
|
<p>多看几遍这段代码就会发现,这里的变量<code>x</code>是定义在<code>if</code>语句里的,但却可以在该语句外面访问到它。究其原因,在于<code>var</code>声明可以在包含它的函数、模块、命名空间或全局作用域内的任何位置被访问到(后面将详细讨论这个问题),而所包含其的代码块却没什么影响。有人就直接叫这种作用域为 <strong>var作用域</strong> ,或 <strong>函数作用域</strong> 。对于函数参数,也适用函数作用域(函数参数也相当于<code>var</code>声明)。</p>
|
|
<p>此规则所涵盖到的作用域,将引发一些错误。比如多次声明同一个变量不会报错,就是其中之一:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sumMatrix</span> (<span class="hljs-params">matrix: <span class="hljs-built_in">number</span>[][]</span>) </span>{
|
|
<span class="hljs-keyword">var</span> sum = <span class="hljs-number">0</span>;
|
|
|
|
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < matrix.length; i++){
|
|
<span class="hljs-keyword">var</span> currentRow = matrix[i];
|
|
|
|
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < currentRow.length; i++){
|
|
sum += currentRow[i];
|
|
}
|
|
}
|
|
|
|
<span class="hljs-keyword">return</span> sum;
|
|
}
|
|
</code></pre>
|
|
<p>显然,内层的<code>for</code>循环会覆盖变量<code>i</code>,因为所有<code>i</code>都引用相同的函数作用域内的变量。稍微有经验的Coder都知道,这些问题可能在代码审查时遗漏,从而引发麻烦。</p>
|
|
<h2 id="捕获变量怪异之处">捕获变量怪异之处</h2>
|
|
<p>看看下面的代码,将有什么样的输出:</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < <span class="hljs-number">10</span>; i++){
|
|
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{
|
|
<span class="hljs-built_in">console</span>.log(i);
|
|
}, <span class="hljs-number">100</span> * i);
|
|
}
|
|
</code></pre>
|
|
<p>对于那些尚不熟悉的Coder,要知道这里的<code>setTimeout</code>会在若干毫秒的延时后尝试执行一个函数(因此要等待其它所有代码执行停止)。</p>
|
|
<p>结果就是:</p>
|
|
<pre><code class="lang-sh">10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
10
|
|
</code></pre>
|
|
<p>很多有经验的JavaScript程序员对此已经很熟悉了,但如被输出吓到了,也不是你一个人。大多数人都期望得到这样的结果:</p>
|
|
<pre><code class="lang-bash">0
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
</code></pre>
|
|
<p>参考上面提到的捕获变量(Capturing Variables),传递给<code>setTimeout</code>的每一个函数表达式,实际上都引用了相同作用域中的同一个<code>i</code>。</p>
|
|
<p>这里有必要花个一分钟来思考一下那意味着什么。<code>setTimeout</code>将在若干毫秒后运行一个函数, <em>但只是</em> 在<code>for</code>循环已停止执行后。随着<code>for</code>循环的停止执行,<code>i</code>的值就成为<code>10</code>。这就是作为<code>setTimeout</code>的第一个参数的函数在调用时,每次都输出<code>10</code>的原因。</p>
|
|
<p>作为解决此问题的一种方法,就是使用立即执行的函数表达式(Immediately Invoked Function Expression, IIFE, <a href="https://segmentfault.com/a/1190000003985390" target="_blank">参考链接</a>)。</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">var</span> i = <span class="hljs-number">0</span>; i < <span class="hljs-number">10</span>; i++){
|
|
<span class="hljs-comment">// 这里要捕获到变量`i`的当前状态</span>
|
|
<span class="hljs-comment">// 是通过触发带有其当前值的一个函数实现的</span>
|
|
(<span class="hljs-function"><span class="hljs-keyword">function</span>(<span class="hljs-params">i</span>)</span>{
|
|
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>)</span>{
|
|
<span class="hljs-built_in">console</span>.log(i);
|
|
}, <span class="hljs-number">100</span> * i)
|
|
})(i);
|
|
}
|
|
</code></pre>
|
|
<p>其实对于这种奇怪的形式,我们都已司空见惯了。立即执行函数中的参数<code>i</code>,会覆盖<code>for</code>循环中的<code>i</code>,但因为使用相同的名称<code>i</code>,所以都不用怎么修改<code>for</code>循环体内部的代码。</p>
|
|
<h2 id="关于全新的let声明方式">关于全新的<code>let</code>声明方式</h2>
|
|
<p>现在已经知道使用<code>var</code>存在诸多问题,这也是要使用<code>let</code>的理由。除了拼写不一样外,<code>let</code>与<code>var</code>的写法一致。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> hello = <span class="hljs-string">'Hello!'</span>;
|
|
</code></pre>
|
|
<p>二者主要的区别,不在于语法上,而是语义的不同,下面会深入研究。</p>
|
|
<h3 id="块作用域(block-scoping)">块作用域(Block Scoping)</h3>
|
|
<p>在使用<code>let</code>来声明某个变量时,使用了 <em>词法作用域(Lexical Scope)</em> ,或 <em>块作用域(Block Scope)</em> 。与使用<code>var</code>声明的变量可在所包含的函数外部访问到不同,块作用域的变量在包含它们的块或<code>for</code>循环之外,是不能访问的。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span> (<span class="hljs-params">input: <span class="hljs-built_in">boolean</span></span>) </span>{
|
|
<span class="hljs-keyword">let</span> a = <span class="hljs-number">100</span>;
|
|
|
|
<span class="hljs-keyword">if</span> (input) {
|
|
<span class="hljs-comment">// 这里仍然可以对`a`进行引用</span>
|
|
<span class="hljs-keyword">let</span> b = a + <span class="hljs-number">1</span>;
|
|
<span class="hljs-keyword">return</span> b;
|
|
}
|
|
|
|
<span class="hljs-comment">// 这样写就会报错:`b` 在这里不存在(error TS2304: Cannot find name 'b'.)</span>
|
|
<span class="hljs-keyword">return</span> b;
|
|
}
|
|
</code></pre>
|
|
<p>上面的代码中定义了两个变量<code>a</code>和<code>b</code>。<code>a</code>的作用域是函数体<code>f</code>内部。而<code>b</code>的作用域为<code>if</code>语句块里。</p>
|
|
<p>在<code>catch</code>语句里声明的变量也具有同样的作用域规则。比如:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">try</span> {
|
|
<span class="hljs-keyword">throw</span> <span class="hljs-string">"oh no!"</span>
|
|
}
|
|
|
|
<span class="hljs-keyword">catch</span> (e) {
|
|
<span class="hljs-built_in">console</span>.log(<span class="hljs-string">"Oh well."</span>)
|
|
}
|
|
|
|
<span class="hljs-comment">// 下面这样会报错:这里不存在`e`</span>
|
|
<span class="hljs-built_in">console</span>.log(e);
|
|
</code></pre>
|
|
<p>块级作用域变量的另一个特点,就是在其被声明之前,是不能访问的(尚未分配内存?)。虽然它们始终“存在”与它们所属的作用域里,但在声明它们的代码之前的部分,被成为 <em>暂时性死区(Temporal Dead Zone, TDZ)</em> (<a href="https://github.com/luqin/exploring-es6-cn/blob/master/md/9.4.md" target="_blank">参考链接</a>)。暂时性死区只是用来说明不能在变量的<code>let</code>语句之前,访问该变量,而TypeScript编译器可以给出这些信息。</p>
|
|
<pre><code class="lang-typescript">a++; <span class="hljs-comment">// error TS2448: Block-scoped variable 'a' used before its declaration. error TS2532: Object is possibly 'undefined'.</span>
|
|
<span class="hljs-keyword">let</span> a;
|
|
</code></pre>
|
|
<p>这里需要注意一点,在一个拥有块作用域的变量被声明之前,仍然可以 <em>获取(capture)</em> 到它。但要在变量被声明前就去调用那个其所属的函数,是不可行的。如编译目标代码是ECMAScript 2015(ES6),那么较新的运行时将抛出一个错误;不过目前的TypeScript编译器尚不能就此进行报错。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">foo</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-comment">// 这里要获取到`a`没有问题(okay to capture `a`)</span>
|
|
|
|
<span class="hljs-keyword">return</span> a;
|
|
}
|
|
|
|
|
|
<span class="hljs-comment">// 但不能在`a`被声明前调用函数`foo`</span>
|
|
<span class="hljs-comment">// 运行时(runtime)应该抛出错误</span>
|
|
|
|
foo();
|
|
|
|
<span class="hljs-keyword">let</span> a;
|
|
</code></pre>
|
|
<p>关于 <em>暂时性死区</em> 的更多信息,请参考<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Statements/let#Temporal_dead_zone_and_errors_with_let" target="_blank">Mozilla开发者网络</a>。</p>
|
|
<h2 id="重定义与屏蔽(re-decalration-and-shadowing)">重定义与屏蔽(Re-decalration and Shadowing)</h2>
|
|
<p>在使用<code>var</code>进行变量声明时,注意到对变量进行多少次声明都没有关系;得到的变量仅有一个。</p>
|
|
<pre><code class="lang-javascript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span> (<span class="hljs-params">x</span>) </span>{
|
|
<span class="hljs-keyword">var</span> x;
|
|
<span class="hljs-keyword">var</span> x;
|
|
|
|
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
|
|
<span class="hljs-keyword">var</span> x;
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>在上面的示例中,对<code>x</code>的所有声明,都是对同一个<code>x</code>的引用,且这样做也毫无问题。但这种做法通常将导致很多bug。<code>let</code>式的声明,终于不会这样任性了。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> x = <span class="hljs-number">10</span>;
|
|
<span class="hljs-keyword">let</span> x = <span class="hljs-number">20</span>; <span class="hljs-comment">// error TS2451: Cannot redeclare block-scoped variable 'x'.</span>
|
|
</code></pre>
|
|
<p>并不是要重复声明的变量,都是块作用域,TypeScript编译器才会给出存在问题的信息。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span> (<span class="hljs-params">x</span>) </span>{
|
|
<span class="hljs-keyword">let</span> x = <span class="hljs-number">100</span>; <span class="hljs-comment">// error TS2300: Duplicate identifier 'x'.</span>
|
|
}
|
|
|
|
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">g</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">let</span> x = <span class="hljs-number">100</span>;
|
|
<span class="hljs-keyword">var</span> x = <span class="hljs-number">100</span>; <span class="hljs-comment">// error TS2451: Cannot redeclare block-scoped variable 'x'.</span>
|
|
}
|
|
</code></pre>
|
|
<p>这并非是说块作用域的变量决不能以某个函数作用域变量加以声明。而是说块作用域变量,只需要在某个明显不同的块中,加以声明。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params">condition, x</span>) </span>{
|
|
<span class="hljs-keyword">if</span> (condition) {
|
|
<span class="hljs-keyword">let</span> x = <span class="hljs-number">100</span>;
|
|
<span class="hljs-keyword">return</span> x;
|
|
}
|
|
|
|
<span class="hljs-keyword">return</span> x;
|
|
}
|
|
|
|
f(<span class="hljs-literal">false</span>, <span class="hljs-number">0</span>); <span class="hljs-comment">// 返回 `0`</span>
|
|
f(<span class="hljs-literal">true</span>, <span class="hljs-number">0</span>); <span class="hljs-comment">// 返回 `100`</span>
|
|
</code></pre>
|
|
<p>这种在某个更深的嵌套块中引入新变量名的做法,就叫 <em>屏蔽(shadowing)</em> 。这样做看起来像是双刃剑,因为无意的屏蔽可能引入某些程序漏洞,同时也可能防止某些漏洞。比如,设想用现在的<code>let</code>变量来重写之前的<code>sumMatrix</code>。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">sumMatrix</span>(<span class="hljs-params">matrix: <span class="hljs-built_in">number</span>[][]</span>) </span>{
|
|
<span class="hljs-keyword">let</span> sum = <span class="hljs-number">0</span>;
|
|
|
|
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i < matrix.length; i++){
|
|
<span class="hljs-keyword">var</span> currentRow = matrix[i];
|
|
|
|
<span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i < currentRow.length; i++){
|
|
sum += currentRow[i];
|
|
}
|
|
}
|
|
}
|
|
</code></pre>
|
|
<p>此版本的循环无疑将正确进行求和了,因为内层循环的<code>i</code>屏蔽了外层循环的<code>i</code>。</p>
|
|
<p>通常为了顾及编写出清爽的代码,应避免使用屏蔽(shadowing)。但在某些情况下使用屏蔽又能带来好处,因此用不用此特性就取决于你的判断了。</p>
|
|
<h3 id="捕获块作用域变量(block-scoped-variable-capturing)">捕获块作用域变量(Block-scoped Variable Capturing)</h3>
|
|
<p>前面在<code>var</code>式声明上,初次接触到 <strong>变量捕获(variable capturing)</strong> 这一概念,主要对所捕获到的变量的行为,有所了解。为了对此有更直观的认识,那么就说在某个作用域运行时,该作用域就创建出一个变量的“环境”。此环境及其所捕获到的变量,就算其作用域中的所有语句执行完毕,也仍将持续存在。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">theCityThatAlwaysSleeps</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">let</span> getCity;
|
|
|
|
<span class="hljs-keyword">if</span> (<span class="hljs-literal">true</span>) {
|
|
<span class="hljs-keyword">let</span> city = <span class="hljs-string">"Seattle"</span>;
|
|
|
|
getCity = <span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{
|
|
<span class="hljs-keyword">return</span> city;
|
|
}
|
|
}
|
|
|
|
<span class="hljs-keyword">return</span> getCity;
|
|
}
|
|
</code></pre>
|
|
<p>上面的代码中,因为在<code>city</code>所在的环境中对其进行了捕获,所以尽管<code>if</code>块完成了执行,却仍可以访问到它。</p>
|
|
<p>回顾之前的<code>setTimeout</code>示例,那里为了捕获<code>for</code>循环的每次迭代下某个变量的状态,而最终使用了一个IIFE。实际上为了所捕获的变量,而是建立了一个新的变量环境。那样做有点痛苦,但幸运的是,在TypeScript中再也无须那样做了。</p>
|
|
<p>在作为某个循环一部分使用<code>let</code>进行变量声明时,这些<code>let</code>声明有着显著不同的行为。与仅仅将一个新的环境引入到该循环相比,这些声明在某种程度上于每次遍历,都创建出一个新的作用域。因此这就跟使用IIFE有着异曲同工的效果,那么就可以仅使用<code>let</code>来改写旧版的<code>setTimeout</code>示例了。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">for</span> (<span class="hljs-keyword">let</span> i = <span class="hljs-number">0</span>; i < <span class="hljs-number">10</span>; i++) {
|
|
setTimeout(<span class="hljs-function"><span class="hljs-keyword">function</span> (<span class="hljs-params"></span>) </span>{ <span class="hljs-built_in">console</span>.log(i); }, <span class="hljs-number">100</span> * i);
|
|
}
|
|
</code></pre>
|
|
<p>将如预期的那样,输出以下结果:</p>
|
|
<pre><code class="lang-bash">0
|
|
1
|
|
2
|
|
3
|
|
4
|
|
5
|
|
6
|
|
7
|
|
8
|
|
9
|
|
</code></pre>
|
|
<h2 id="关于const式的声明">关于<code>const</code>式的声明</h2>
|
|
<p><code>const</code>式声明是声明变量的另一种方式。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> numLivesForCat = <span class="hljs-number">9</span>;
|
|
</code></pre>
|
|
<p>此类声明与<code>let</code>声明相似,但如同它们的名称一样,经由<code>const</code>修饰的变量的值,一旦被绑定,就不能加以改变了。也就是说,这些变量与<code>let</code>式声明有着相同的作用域,但不能对其进行再度赋值。</p>
|
|
<p>注意不要与所谓某些所引用的值 <em>不可修改(immutable)</em> 之概念搞混(经<code>const</code>修饰变量与那些不可修改值并不是一个东西)。</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">const</span> numLivesForCat = <span class="hljs-number">9</span>;
|
|
|
|
<span class="hljs-keyword">const</span> kitty = {
|
|
name: <span class="hljs-string">"Aurora"</span>,
|
|
numLives: numLivesForCat
|
|
}
|
|
|
|
<span class="hljs-comment">// 下面的代码将报错</span>
|
|
|
|
kitty = {
|
|
name: <span class="hljs-string">"Danielle"</span>,
|
|
numLives: numLivesForCat
|
|
};
|
|
|
|
<span class="hljs-comment">// 但这些代码都没有问题</span>
|
|
kitty.name = <span class="hljs-string">"Rory"</span>;
|
|
kitty.name = <span class="hljs-string">"Kitty"</span>;
|
|
kitty.name = <span class="hljs-string">"Cat"</span>;
|
|
kitty.numLives--;
|
|
</code></pre>
|
|
<p>上面的示例表明,除非采取了特别措施加以避免,某个<code>const</code>变量的内部状态仍然是可改变的。不过恰好TypeScript提供了将对象成员指定为<code>readonly</code>的方法。<a href="">接口</a>那一章对此进行了讨论。</p>
|
|
<h2 id="let与const的比较"><code>let</code>与<code>const</code>的比较</h2>
|
|
<p>现在有了两种在作用域语义上类似的变量声明方式,那自然就要发出到底要使用哪种方式的疑问。与那些最为宽泛的问题一样,答案就是看具体情况。</p>
|
|
<p>适用<a href="https://en.wikipedia.org/wiki/Principle_of_least_privilege" target="_blank">最小权限原则</a>,除开那些将进行修改的变量,所有变量都应使用<code>const</code>加以声明。这么做的理论基础就是,在某个变量无需写入时,在同一代码基础上工作的其他人就不应自动地被赋予对该对象写的权力,同时将需要考虑他们是否真的需要对该变量进行重新赋值。使用<code>const</code>还可以在对数据流进行推演时,令到代码更可预测。</p>
|
|
<p>总之需要三思而后行,同时在可行的情况下,应就此与团队的其它人共商此事。</p>
|
|
<p>本手册主要使用<code>let</code>声明。</p>
|
|
<h2 id="解构(destructuring)及新语法">解构(Destructuring)及新语法<code>...</code></h2>
|
|
<p>TypeScript从ECMAScript 2015(ES6)那里借鉴的另一特性,就是 <strong>解构</strong> 。可从<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Operators/Destructuring_assignment" target="_blank">Mozilla开发者网络</a>对结构这一全新特性做完整了解。此小节将做简短的概览。</p>
|
|
<h3 id="数组的解构">数组的解构</h3>
|
|
<p>解构的最简单形式,就是数组结构式赋值(array destructuring assignment)了:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> input: <span class="hljs-built_in">number</span>[] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>];
|
|
<span class="hljs-keyword">let</span> [first, second] = input;
|
|
|
|
<span class="hljs-built_in">console</span>.log(first); <span class="hljs-comment">// 输出 1</span>
|
|
<span class="hljs-built_in">console</span>.log(second); <span class="hljs-comment">// 输出 2</span>
|
|
</code></pre>
|
|
<p>上面的代码,创建了两个分别名为<code>first</code>及<code>second</code>的变量。这与使用索引效果一样,却更为方便:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> [first, second];
|
|
first = input[<span class="hljs-number">0</span>];
|
|
second = input[<span class="hljs-number">1</span>];
|
|
</code></pre>
|
|
<p>对于那些已经声明的变量,解构也工作:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-comment">// 对变量的交换操作</span>
|
|
[first, second] = [second, first];
|
|
</code></pre>
|
|
<p>以及对某个函数参数的解构:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span> (<span class="hljs-params"> [first, second]: [<span class="hljs-built_in">number</span>, <span class="hljs-built_in">number</span>] </span>) </span>{
|
|
<span class="hljs-built_in">console</span>.log(first);
|
|
<span class="hljs-built_in">console</span>.log(second);
|
|
}
|
|
|
|
f([<span class="hljs-number">1</span>, <span class="hljs-number">2</span>]);
|
|
</code></pre>
|
|
<p>使用 <strong>语法<code>...</code></strong> ,可为某个清单(list, 也就是数组)中剩下的条目创建一个变量:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> [first, ...remain] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
|
|
|
|
<span class="hljs-built_in">console</span>.log(first);
|
|
<span class="hljs-built_in">console</span>.log(remain);
|
|
</code></pre>
|
|
<p>因为这是JavaScript, 所以当然可以将那些不在乎的后续元素,简单地忽视掉:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> [first] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
|
|
<span class="hljs-built_in">console</span>.log(first); <span class="hljs-comment">// 输出 1</span>
|
|
</code></pre>
|
|
<p>或仅结构其它元素:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> [, second, , fourth] = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>, <span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
|
|
</code></pre>
|
|
<h3 id="对象的解构(object-destructuring)">对象的解构(Object destructuring)</h3>
|
|
<p>还可以解构对象:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> o = {
|
|
a: <span class="hljs-string">"foo"</span>,
|
|
b: <span class="hljs-number">12</span>,
|
|
c: <span class="hljs-string">"bar"</span>
|
|
};
|
|
|
|
<span class="hljs-keyword">let</span> {a, b} = <span class="hljs-number">0</span>;
|
|
</code></pre>
|
|
<p>这段代码将从<code>o.a</code>与<code>o.b</code>创建出两个新变量<code>a</code>与<code>b</code>。请注意在不需要<code>c</code>时可跳过它。</p>
|
|
<p>与数组解构一样,可不加声明地进行赋值:</p>
|
|
<pre><code class="lang-typescript">({a, b} = {a: <span class="hljs-string">"baz"</span>, b: <span class="hljs-number">101</span>});
|
|
</code></pre>
|
|
<p>请注意这里必须将该语句用括号(<code>()</code>)括起来。因为 <strong>JavaScript会将<code>{</code>解析为代码块的开始</strong> 。</p>
|
|
<p>使用<code>...</code>语法,可为某个对象中的剩余条目,创建一个变量:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> {a, ...passthrough} = o;
|
|
<span class="hljs-keyword">let</span> total = passthrough.length + passthrough.c.length;
|
|
</code></pre>
|
|
<h3 id="属性的重命名(新语法)">属性的重命名(新语法)</h3>
|
|
<p>给属性赋予不同的名称,也是可以的:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> {a: newName1, b: newName2} = o;
|
|
</code></pre>
|
|
<p>从这里开始,此新语法就有点令人迷惑了。建议将<code>a: newName1</code>读作<code>a</code>作为<code>newName1</code>("<code>a</code> as <code>newName1</code>")。其方向是左到右(left-to-right)的, 就如同以前写的:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> newName1 = o.a;
|
|
<span class="hljs-keyword">let</span> newName2 = o.b;
|
|
</code></pre>
|
|
<p>此外,这里的冒号(<code>:</code>)也不是指的类型。如果要指定类型,仍然需要写道整个解构的后面:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> {a, b} : {a: <span class="hljs-built_in">string</span>, b: <span class="hljs-built_in">number</span>} = o;
|
|
</code></pre>
|
|
<h3 id="对象解构的默认值(default-values-新语法)">对象解构的默认值(Default values, 新语法)</h3>
|
|
<p>默认值令到在某属性未被定义时,为其指派一个默认值成为可能:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">keepWholeObject</span> (<span class="hljs-params"> wholeObject: {a: <span class="hljs-built_in">string</span>, b?: <span class="hljs-built_in">number</span>} </span>) </span>{
|
|
<span class="hljs-keyword">let</span> {a, b = <span class="hljs-number">1001</span>} = wholeObject;
|
|
|
|
<span class="hljs-comment">// do some stuff</span>
|
|
}
|
|
</code></pre>
|
|
<p>就算<code>b</code>未被定义,上面的<code>keepWholeObject</code>函数也会有着一个<code>wholeObject</code>变量,以及属性<code>a</code>与<code>b</code>。</p>
|
|
<h3 id="对象解构下的函数声明(function-declarations)">对象解构下的函数声明(Function declarations)</h3>
|
|
<p>在函数声明中,解构也可运作。在简单场合,这是很明了的:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">type</span> C = { a: <span class="hljs-built_in">string</span>, b?: <span class="hljs-built_in">number</span> };
|
|
|
|
<span class="hljs-function"><span class="hljs-keyword">function</span> <span class="hljs-title">f</span>(<span class="hljs-params"> {a, b}: C </span>) <span class="hljs-title">void</span> </span>{
|
|
<span class="hljs-comment">// do some stuffs</span>
|
|
}
|
|
</code></pre>
|
|
<p>给参数指定默认值,是更为通常的做法,而通过解构来获取默认值,却可能是难以掌握的。首先需要记住在默认值前加上模式(<code>C</code>?):</p>
|
|
<pre><code class="lang-typescript">function f ({a, b} = {a: "", b: 0}): avoid {
|
|
// do some stuffs
|
|
}
|
|
|
|
f(); // 编译通过, 默认值为: {a: "", b: 0}
|
|
</code></pre>
|
|
<blockquote>
|
|
<p>上面这段代码是类型推理(type inference)的一个示例,本手册后面后讲到。</p>
|
|
</blockquote>
|
|
<p>此时,就要记住是要在被解构的属性上,而不是主初始化器上,给可选属性赋予一个默认值(Then, you need to remember to give a default for optional properties on the destructured property instead of the main initializer)。记住<code>C</code>的定义带有可选的<code>b</code>:</p>
|
|
<pre><code class="lang-typescript">function f ({ a, b = 0 } = { a: "" }): void {
|
|
//...
|
|
}
|
|
|
|
f ({a: "yes"}); // 可通过编译,默认 b = 0
|
|
f (); // 可通过编译,默认 {a: ""}, 此时默认这里b = 0
|
|
f({}); // 报错,在提供了一个参数时,就需要提供`a`
|
|
</code></pre>
|
|
<p>请小心谨慎地使用解构。如前面的示例所演示的那样,就算是最简单的解构表达式也不是那么容易理解。而在有着较深的嵌套解构时,即便不带有重命名、默认值及类型注释等操作,也难于掌握,那么就尤其容易搞混了。请尽量保持解构表达式在较小及简单的状态。可一致只写那些可以自己生成的赋值解构。</p>
|
|
<h2 id="扩展(spread-新语法)">扩展(Spread, 新语法)</h2>
|
|
<p>扩展操作符(The spread operator)与解构相反。经由扩展运算符,就可以将一个数组,展开到另一个中去,或者将一个对象展开到另一对象中去。比如:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> first = [<span class="hljs-number">1</span>, <span class="hljs-number">2</span>],
|
|
second = [<span class="hljs-number">3</span>, <span class="hljs-number">4</span>];
|
|
|
|
<span class="hljs-keyword">let</span> bothPlus = [<span class="hljs-number">0</span>, ...first, ...second, <span class="hljs-number">5</span>];
|
|
</code></pre>
|
|
<p>这段代码赋予<code>bothPlus</code>值<code>[0, 1, 2, 3, 4, 5]</code>。展开(spreading)创建出<code>first</code>与<code>second</code>变量的影子拷贝(a shadow copy)。而两个变量则并不会被展开操作所改变。</p>
|
|
<p>对于对象,也可以对其展开:</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">let</span> defaults = { food: <span class="hljs-string">"spicy"</span>, price: <span class="hljs-string">"$$"</span>, ambiance: <span class="hljs-string">"noisy"</span> };
|
|
|
|
<span class="hljs-keyword">let</span> search = { ...defaults, food: <span class="hljs-string">"rich"</span> };
|
|
</code></pre>
|
|
<p>现在<code>search</code>就成了<code>{ food: "rich", price: "$$", ambiance: "noisy" }</code>。比起数组展开,对象展开 <strong>要复杂一些</strong> 。与数组展开一样,对象展开将从左到右进行处理(proceeds from left-to-right),但结果仍是一个对象。这就是说在展开对象中后来的属性,将覆盖先来的属性。所以加入将上面的示例修改为在末尾才进行展开:</p>
|
|
<pre><code>let defaults = { food: "spicy", price: "$$", ambiance: "noisy" };
|
|
|
|
let search = { food: "rich", ...defaults };
|
|
</code></pre><p>此时<code>defaults</code>中的<code>food</code>属性就将覆盖<code>food: "rich"</code>,然而这并不是我们想要的。</p>
|
|
<p>对象的展开还有其它一些令人惊讶的限制。首先,它仅包含某对象<a href="https://developer.mozilla.org/en-US/docs/Web/JavaScript/Enumerability_and_ownership_of_properties" target="_blank">自己的、可枚举属性(own, enumerable properties)</a>。简单地说,这就意味着在展开某对象实例时,将丢失它的那些方法(Basically, that means you lose methods when you spread instances of an object):</p>
|
|
<pre><code class="lang-typescript"><span class="hljs-keyword">class</span> C {
|
|
p = <span class="hljs-number">12</span>;
|
|
m () {
|
|
}
|
|
}
|
|
|
|
<span class="hljs-keyword">let</span> c = <span class="hljs-keyword">new</span> C();
|
|
<span class="hljs-keyword">let</span> clone = { ...c };
|
|
|
|
clone.p; <span class="hljs-comment">// 没有问题</span>
|
|
clone.m(); <span class="hljs-comment">// 报错!error TS2339: Property 'm' does not exist on type '{ p: number; }'.</span>
|
|
</code></pre>
|
|
<p>此外,TypeScript编译器不支持一般函数的类型参数(the TypeScript compiler doesn't allow spreads of type parameters from generic functions)。此特性有望在该语言的后期发布中受到支持。</p>
|
|
|
|
|
|
</section>
|
|
|
|
</div>
|
|
<div class="search-results">
|
|
<div class="has-results">
|
|
|
|
<h1 class="search-results-title"><span class='search-results-count'></span> results matching "<span class='search-query'></span>"</h1>
|
|
<ul class="search-results-list"></ul>
|
|
|
|
</div>
|
|
<div class="no-results">
|
|
|
|
<h1 class="search-results-title">No results matching "<span class='search-query'></span>"</h1>
|
|
|
|
</div>
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
</div>
|
|
|
|
</div>
|
|
|
|
|
|
|
|
<a href="01_basic_data_types.html" class="navigation navigation-prev " aria-label="Previous page: 基本数据类型">
|
|
<i class="fa fa-angle-left"></i>
|
|
</a>
|
|
|
|
|
|
<a href="03_classes.html" class="navigation navigation-next " aria-label="Next page: 类">
|
|
<i class="fa fa-angle-right"></i>
|
|
</a>
|
|
|
|
|
|
|
|
</div>
|
|
|
|
<script>
|
|
var gitbook = gitbook || [];
|
|
gitbook.push(function() {
|
|
gitbook.page.hasChanged({"page":{"title":"变量声明","level":"1.3","depth":1,"next":{"title":"类","level":"1.4","depth":1,"path":"03_classes.md","ref":"03_classes.md","articles":[]},"previous":{"title":"基本数据类型","level":"1.2","depth":1,"path":"01_basic_data_types.md","ref":"01_basic_data_types.md","articles":[]},"dir":"ltr"},"config":{"gitbook":"*","theme":"default","variables":{},"plugins":["livereload"],"pluginsConfig":{"livereload":{},"highlight":{},"search":{},"lunr":{"ignoreSpecialCharacters":false,"maxIndexSize":1000000},"sharing":{"weibo":false,"all":["facebook","google","twitter","weibo","instapaper"],"google":false,"twitter":true,"vk":false,"instapaper":false,"facebook":true},"fontsettings":{"theme":"white","family":"sans","size":2},"theme-default":{"styles":{"website":"styles/website.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css","pdf":"styles/pdf.css","epub":"styles/epub.css"},"showLevel":false}},"structure":{"langs":"LANGS.md","readme":"README.md","glossary":"GLOSSARY.md","summary":"SUMMARY.md"},"pdf":{"pageNumbers":true,"fontSize":12,"fontFamily":"Arial","paperSize":"a4","chapterMark":"pagebreak","pageBreaksBefore":"/","margin":{"right":62,"left":62,"top":56,"bottom":56}},"styles":{"website":"styles/website.css","mobi":"styles/mobi.css","ebook":"styles/ebook.css","print":"styles/print.css","pdf":"styles/pdf.css","epub":"styles/epub.css"}},"file":{"path":"02_variables_declaration.md","mtime":"2019-04-03T06:43:16.304Z","type":"markdown"},"gitbook":{"version":"3.2.3","time":"2019-04-04T00:04:23.982Z"},"basePath":".","book":{"language":""}});
|
|
});
|
|
</script>
|
|
</div>
|
|
|
|
|
|
<script src="gitbook/gitbook.js"></script>
|
|
<script src="gitbook/theme.js"></script>
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-livereload/plugin.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-search/search-engine.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-search/search.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-lunr/lunr.min.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-lunr/search-lunr.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-sharing/buttons.js"></script>
|
|
|
|
|
|
|
|
<script src="gitbook/gitbook-plugin-fontsettings/fontsettings.js"></script>
|
|
|
|
|
|
|
|
</body>
|
|
</html>
|
|
|