Skip to content

Commit c4f8d5d

Browse files
committed
merging all conflicts
2 parents 9c919ba + d78b01e commit c4f8d5d

File tree

432 files changed

+10497
-2260
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

432 files changed

+10497
-2260
lines changed

.github/FUNDING.yml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
github: iliakan

.gitignore

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,3 +21,4 @@ sftp-config.json
2121
Thumbs.db
2222

2323

24+
/svgs

1-js/01-getting-started/1-intro/article.md

Lines changed: 79 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,18 @@
11
# 介紹 JavaScript
22

3+
<<<<<<< HEAD
34
一起來看看 JavaScript 有什麼特別的,我們能做些什麼,與哪些配合不錯的技術。
5+
=======
6+
Let's see what's so special about JavaScript, what we can achieve with it, and what other technologies play well with it.
7+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
48
59
## 什麼是 JavaScript?
610

11+
<<<<<<< HEAD
712
*JavaScript* 最初是為了 *"賦予網頁活力"* 而創造的。
13+
=======
14+
*JavaScript* was initially created to "make web pages alive".
15+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
816
917
這種程式語言我們稱之為 *腳本*,它們可以被寫入網頁 HTML 中,並在頁面讀取時自動執行。
1018

@@ -24,26 +32,44 @@
2432

2533
不同的引擎有不同的 "代號(codenames)"。例如:
2634

35+
<<<<<<< HEAD
2736
- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- Chrome 和 Opera 內的引擎。
2837
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- Firefox 內的引擎。
2938
- ... 還有其他代號,像是不同版本 IE 使用的 "Trident" 與 "Chakra"、微軟 Edge 的 "ChakraCore"、Safari 的 "Nitro" 與 "SquirrelFish",等等。
3039

3140
上面提到的代號最好可以記住,因為這些代號常被用於網路上的開發者文章,就像我們一樣。如:"V8 支援某個 X 功能",代表該功能在 Chrome 和 Opera 上應該可以運作。
41+
=======
42+
- [V8](https://en.wikipedia.org/wiki/V8_(JavaScript_engine)) -- in Chrome, Opera and Edge.
43+
- [SpiderMonkey](https://en.wikipedia.org/wiki/SpiderMonkey) -- in Firefox.
44+
- ...There are other codenames like "Chakra" for IE, "JavaScriptCore", "Nitro" and "SquirrelFish" for Safari, etc.
45+
46+
The terms above are good to remember because they are used in developer articles on the internet. We'll use them too. For instance, if "a feature X is supported by V8", then it probably works in Chrome, Opera and Edge.
47+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
3248
3349
```smart header="引擎怎麼運作的?"
3450
3551
引擎很複雜,但概念很簡單。
3652
53+
<<<<<<< HEAD
3754
1. 引擎(瀏覽器內建)讀取("解析")腳本
3855
2. 接著轉換("編譯")腳本為機器語言
3956
3. 然後機器語言極快地執行
57+
=======
58+
1. The engine (embedded if it's a browser) reads ("parses") the script.
59+
2. Then it converts ("compiles") the script to machine code.
60+
3. And then the machine code runs, pretty fast.
61+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
4062
4163
引擎會對流程中每個階段進行優化。甚至會在執行時監看編譯好的腳本,分析其資料流,並以此再優化機器碼。
4264
```
4365

4466
## 瀏覽器中的 JavaScript 可以做什麼?
4567

68+
<<<<<<< HEAD
4669
現代化 JavaScript 是個 "安全" 的程式語言。它不提供對記憶體或 CPU 的低階存取,因為它原生是為了瀏覽器而建立,所以不需要。
70+
=======
71+
Modern JavaScript is a "safe" programming language. It does not provide low-level access to memory or the CPU, because it was initially created for browsers which do not require it.
72+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
4773
4874
JavaScript 的能力很大一部分取決於執行它的環境。例如 [Node.js](https://wikipedia.org/wiki/Node.js) 提供 JavaScript 可以讀寫任意檔案與發送網路請求(network requests)等功能。
4975

@@ -59,14 +85,23 @@ JavaScript 的能力很大一部分取決於執行它的環境。例如 [Node.js
5985

6086
## 瀏覽器中的 JavaScript **不能**做什麼?
6187

88+
<<<<<<< HEAD
6289
為了使用者的資訊安全,JavaScript 在瀏覽器內的功能被限制。此為防範惡意網頁獲取私人資訊或損害使用者資料。
90+
=======
91+
JavaScript's abilities in the browser are limited to protect the user's safety. The aim is to prevent an evil webpage from accessing private information or harming the user's data.
92+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
6393
6494
這些限制範例如下:
6595

96+
<<<<<<< HEAD
6697
- 網頁上的 JavaScript 無法讀寫、複製和執行硬碟內任意檔案。它也沒有直接存取作業系統的功能。
98+
=======
99+
- JavaScript on a webpage may not read/write arbitrary files on the hard disk, copy them or execute programs. It has no direct access to OS functions.
100+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
67101
68102
現代化瀏覽器允許 JavaScript 有限制地操作檔案,且只有在使用者做特定動作時提供,像是:"拖曳" 一個檔案至瀏覽器視窗,或經由 `<input>` 標籤選取。
69103

104+
<<<<<<< HEAD
70105
JavaScript 有些方法可與相機、麥克風或其他裝置互動,但都需要使用者明確地授權。所以啟用 JavaScript 的網頁不會偷偷開啟相機觀察周遭並傳資料給 [美國國家安全局(NSA)](https://en.wikipedia.org/wiki/National_Security_Agency)
71106
- 不同的瀏覽器分頁/視窗基本上不知道彼此,但有時例外,例如:當一個視窗使用 JavaScript 開啟另一個視窗時。但就算如此,開啟不同網站(不同域名、通訊協定或埠)的頁面,其中的 JavaScript 亦無法溝通。
72107

@@ -78,44 +113,88 @@ JavaScript 的能力很大一部分取決於執行它的環境。例如 [Node.js
78113
![](limitations.svg)
79114

80115
在瀏覽器以外的 JavaScript 就沒有這些限制,如:伺服器上的 JavaScript。現代化瀏覽器也允許插件/擴充套件要求額外權限。
116+
=======
117+
There are ways to interact with the camera/microphone and other devices, but they require a user's explicit permission. So a JavaScript-enabled page may not sneakily enable a web-camera, observe the surroundings and send the information to the [NSA](https://en.wikipedia.org/wiki/National_Security_Agency).
118+
- Different tabs/windows generally do not know about each other. Sometimes they do, for example when one window uses JavaScript to open the other one. But even in this case, JavaScript from one page may not access the other page if they come from different sites (from a different domain, protocol or port).
119+
120+
This is called the "Same Origin Policy". To work around that, *both pages* must agree for data exchange and must contain special JavaScript code that handles it. We'll cover that in the tutorial.
121+
122+
This limitation is, again, for the user's safety. A page from `http://anysite.com` which a user has opened must not be able to access another browser tab with the URL `http://gmail.com`, for example, and steal information from there.
123+
- JavaScript can easily communicate over the net to the server where the current page came from. But its ability to receive data from other sites/domains is crippled. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.
124+
125+
![](limitations.svg)
126+
127+
Such limitations do not exist if JavaScript is used outside of the browser, for example on a server. Modern browsers also allow plugins/extensions which may ask for extended permissions.
128+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
81129
82130
## 是什麼讓 JavaScript 如此獨特?
83131

84132
至少有 *三項* JavaScript 很棒的事:
85133

86134
```compare
135+
<<<<<<< HEAD
87136
+ 與 HTML/CSS 完整整合
88137
+ 簡單的事能夠簡單地完成
89138
+ 所有主要瀏覽器支援且預設開啟
139+
=======
140+
+ Full integration with HTML/CSS.
141+
+ Simple things are done simply.
142+
+ Supported by all major browsers and enabled by default.
143+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
90144
```
91145
在瀏覽器技術中,只有 JavaScript 能唯一滿足這三項。
92146

93147
這造就 JavaScript 如此獨特。這也是為什麼它是建立瀏覽器介面最為廣泛的工具。
94148

149+
<<<<<<< HEAD
95150
此外,JavaScript 也可以建立伺服器和手機應用程式等等。
151+
=======
152+
That said, JavaScript can be used to create servers, mobile applications, etc.
153+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
96154
97155
## JavaScript "之上" 的語言
98156

99157
JavaScript 的語法並不符合每個人的要求,不同人想要不同功能。
100158

101159
這是預期中的,因為每個人的計畫和需求都不一樣。
102160

161+
<<<<<<< HEAD
103162
所以最近有大量新語言出現,它們在被瀏覽器執行前,都被 *轉譯*(transpiled)成 JavaScript。
163+
=======
164+
So, recently a plethora of new languages appeared, which are *transpiled* (converted) to JavaScript before they run in the browser.
165+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
104166
105167
現代化的工具讓轉譯迅速且透明,且實際上使開發者用另一種語言寫程式,再被自行轉換成 JavaScript。
106168

107169
例如這些語言:
108170

171+
<<<<<<< HEAD
109172
- [CoffeeScript](http://coffeescript.org/) 是組 JavaScript 的 "語法糖"。它有更簡短的語法,可以讓我們寫出更清楚且精確的程式碼,通常 Ruby 開發者愛用。
110173
- [TypeScript](http://www.typescriptlang.org/) 致力於增加 "強型態確認(strict data typing)" 來簡化開發與支援複雜的系統,為微軟所開發。
111174
- [Flow](http://flow.org/) 同樣增加型態確認但使用不同方式,為臉書所開發。
112175
- [Dart](https://www.dartlang.org/) 是一種擁有自己引擎的獨立語言,它執行在非瀏覽器環境上(像是手機應用程式),但也可以轉譯成 JavaScript,為谷歌所開發。
113176

114177
還有更多其他語言。當然,就算我們使用某種轉譯式語言,我們應該也要了解 JavaScript 來真正知道我們在做什麼。
178+
=======
179+
- [CoffeeScript](https://coffeescript.org/) is "syntactic sugar" for JavaScript. It introduces shorter syntax, allowing us to write clearer and more precise code. Usually, Ruby devs like it.
180+
- [TypeScript](https://www.typescriptlang.org/) is concentrated on adding "strict data typing" to simplify the development and support of complex systems. It is developed by Microsoft.
181+
- [Flow](https://flow.org/) also adds data typing, but in a different way. Developed by Facebook.
182+
- [Dart](https://www.dartlang.org/) is a standalone language that has its own engine that runs in non-browser environments (like mobile apps), but also can be transpiled to JavaScript. Developed by Google.
183+
- [Brython](https://brython.info/) is a Python transpiler to JavaScript that enables the writing of applications in pure Python without JavaScript.
184+
- [Kotlin](https://kotlinlang.org/docs/reference/js-overview.html) is a modern, concise and safe programming language that can target the browser or Node.
185+
186+
There are more. Of course, even if we use one of these transpiled languages, we should also know JavaScript to really understand what we're doing.
187+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
115188
116189
## 總結
117190

118191
- JavaScript 最初被建為只用在瀏覽器上的語言,但現在也被其他多種環境所使用。
119192
- 至今 JavaScript 有著獨特的地位,它是在瀏覽器上最被廣泛採用的語言且與 HTML/CSS 完整整合。
120193
- 有許多語言可被 "轉譯" 成 JavaScript 並提供特定的功能。建議在掌握 JavaScript 後可以稍微看看。
121194

195+
<<<<<<< HEAD
196+
=======
197+
- JavaScript was initially created as a browser-only language, but it is now used in many other environments as well.
198+
- Today, JavaScript has a unique position as the most widely-adopted browser language, fully integrated with HTML/CSS.
199+
- There are many languages that get "transpiled" to JavaScript and provide certain features. It is recommended to take a look at them, at least briefly, after mastering JavaScript.
200+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3

1-js/01-getting-started/2-manuals-specifications/article.md

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,22 +2,35 @@
22

33
這本書是個 *教程*,主要是幫助你漸漸地學會這門語言,一旦你熟悉了基礎,你將會需要更多其他的資源。
44

5+
<<<<<<< HEAD
56
## 規格書
7+
=======
8+
This book is a *tutorial*. It aims to help you gradually learn the language. But once you're familiar with the basics, you'll need other resources.
9+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
610
711
[The ECMA-262 specification](https://www.ecma-international.org/publications/standards/Ecma-262.htm) 規格書包含了 JavaScript 最深入、詳細以及形式化的資訊。它定義了這門語言。
812

913
但就因為它太形式化了,一開始你會很難讀得懂。如果你需要關於這門語言最可靠的資源,來看規格書就對了,但它不太適合你拿來日常使用。
1014

1115
每年都會有新規格版本釋出,這些釋出版本之間的最新規格草案在這 <https://tc39.es/ecma262/>
1216

17+
<<<<<<< HEAD
1318
如果你想知道最尖端的功能,包含那些 "即將成為標準"(所謂 "stage 3")的功能,可以看一下 <https://github.com/tc39/proposals>
19+
=======
20+
A new specification version is released every year. Between these releases, the latest specification draft is at <https://tc39.es/ecma262/>.
21+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
1422
1523
同樣地,假如你在開發瀏覽器相關的功能,我們也有在此教程的 [第二部分](info:browser-environment) 介紹相關的規格書。
1624

25+
<<<<<<< HEAD
1726
## 操作手冊
27+
=======
28+
Also, if you're developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial.
29+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
1830
1931
- **MDN (Mozilla) JavaScript Reference** 是一個包含了範例以及其他資訊的操作手冊,很適合拿來獲取個別函式或是方法的深入資訊。
2032

33+
<<<<<<< HEAD
2134
你可以在這裡找到 <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>
2235

2336
不過,透過網路搜尋通常會是較好的選擇。使用在搜尋列打入 "MDN [關鍵字]" 的方式,比如你要搜尋 `parseInt` 這個函式,可以用 <https://google.com/search?q=MDN+parseInt>。
@@ -29,6 +42,13 @@
2942
## 兼容表
3043

3144
JavaScript 是一個持續開發中的語言,它定期會被加入一些新功能。
45+
=======
46+
- **MDN (Mozilla) JavaScript Reference** is the main manual with examples and other information. It's great to get in-depth information about individual language functions, methods etc.
47+
48+
You can find it at <https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference>.
49+
50+
Although, it's often best to use an internet search instead. Just use "MDN [term]" in the query, e.g. <https://google.com/search?q=MDN+parseInt> to search for the `parseInt` function.
51+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
3252
3353
想知道瀏覽器或是其他引擎的支援程度,可以參考:
3454

@@ -37,5 +57,14 @@ JavaScript 是一個持續開發中的語言,它定期會被加入一些新功
3757

3858
所有這些資訊對於實務開發都是很有用的,因為他們包含了非常有價值的資訊,比如支援程度跟語言的細節等。
3959

60+
<<<<<<< HEAD
4061
當你需要比較深入的資訊或是需要了解一些特定的功能時,請記得使用這些資訊(或是此頁)。
4162

63+
=======
64+
- <https://caniuse.com> - per-feature tables of support, e.g. to see which engines support modern cryptography functions: <https://caniuse.com/#feat=cryptography>.
65+
- <https://kangax.github.io/compat-table> - a table with language features and engines that support those or don't support.
66+
67+
All these resources are useful in real-life development, as they contain valuable information about language details, their support, etc.
68+
69+
Please remember them (or this page) for the cases when you need in-depth information about a particular feature.
70+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3

1-js/01-getting-started/3-code-editors/article.md

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,8 +12,13 @@
1212

1313
如果你還沒選擇使用一個 IDE,可以考慮以下選擇:
1414

15+
<<<<<<< HEAD
1516
- [Visual Studio Code](https://code.visualstudio.com/)(跨平台,免費)。
1617
- [WebStorm](http://www.jetbrains.com/webstorm/)(跨平台,付費)。
18+
=======
19+
- [Visual Studio Code](https://code.visualstudio.com/) (cross-platform, free).
20+
- [WebStorm](https://www.jetbrains.com/webstorm/) (cross-platform, paid).
21+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
1722
1823
若使用 Windows 系統,也可選用 "Visual Studio",但別跟 "Visual Studio Code" 搞混了。"Visual Studio" 是一個需付費且強大的 Windows 專屬編輯器,特別適合開發 .NET 平台,用來開發 JavaScript 也不錯。它有個免費的版本 [Visual Studio Community](https://www.visualstudio.com/vs/community/)
1924

@@ -29,13 +34,21 @@
2934

3035
實際上,輕量化編輯器可能有各式各樣的插件,包含目錄語法層級分析與自動程式補完,所以兩者間並沒有明顯的界線。
3136

37+
<<<<<<< HEAD
3238
以下是一些值得考慮的選擇:
3339

3440
- [Atom](https://atom.io/)(跨平台,免費)。
3541
- [Visual Studio Code](https://code.visualstudio.com/)(跨平台,免費).
3642
- [Sublime Text](http://www.sublimetext.com)(跨平台,共享軟體)。
3743
- [Notepad++](https://notepad-plus-plus.org/)(Windows,免費)。
3844
- [Vim](http://www.vim.org/)[Emacs](https://www.gnu.org/software/emacs/) 也很不錯,前提是你要知道怎麼使用。
45+
=======
46+
There are many options, for instance:
47+
48+
- [Sublime Text](https://www.sublimetext.com/) (cross-platform, shareware).
49+
- [Notepad++](https://notepad-plus-plus.org/) (Windows, free).
50+
- [Vim](https://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.
51+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3
3952
4053
## 不要起爭議
4154

@@ -45,3 +58,12 @@
4558

4659
選擇編輯器就像選其他工具一樣,需要依照你的專案、習慣和個人喜好選擇。
4760

61+
<<<<<<< HEAD
62+
=======
63+
The choice of an editor, like any other tool, is individual and depends on your projects, habits, and personal preferences.
64+
65+
The author's personal opinion:
66+
67+
- I'd use [Visual Studio Code](https://code.visualstudio.com/) if I develop mostly frontend.
68+
- Otherwise, if it's mostly another language/platform and partially frontend, then consider other editors, such as XCode (Mac), Visual Studio (Windows) or Jetbrains family (Webstorm, PHPStorm, RubyMine etc, depending on the language).
69+
>>>>>>> d78b01e9833009fab534462e05c03cffc51bf0e3

0 commit comments

Comments
 (0)