You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
上面提到的代號最好可以記住,因為這些代號常被用於網路上的開發者文章,就像我們一樣。如:"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
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
32
48
33
49
```smart header="引擎怎麼運作的?"
34
50
35
51
引擎很複雜,但概念很簡單。
36
52
53
+
<<<<<<< HEAD
37
54
1. 引擎(瀏覽器內建)讀取("解析")腳本
38
55
2. 接著轉換("編譯")腳本為機器語言
39
56
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
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
40
62
41
63
引擎會對流程中每個階段進行優化。甚至會在執行時監看編譯好的腳本,分析其資料流,並以此再優化機器碼。
42
64
```
43
65
44
66
## 瀏覽器中的 JavaScript 可以做什麼?
45
67
68
+
<<<<<<< HEAD
46
69
現代化 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.
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.
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 severely limited. Though possible, it requires explicit agreement (expressed in HTTP headers) from the remote side. Once again, that's a safety limitation.
124
+
125
+

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
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
81
129
82
130
## 是什麼讓 JavaScript 如此獨特?
83
131
84
132
至少有 *三項* JavaScript 很棒的事:
85
133
86
134
```compare
135
+
<<<<<<< HEAD
87
136
+ 與 HTML/CSS 完整整合
88
137
+ 簡單的事能夠簡單地完成
89
138
+ 所有主要瀏覽器支援且預設開啟
139
+
=======
140
+
+ Full integration with HTML/CSS.
141
+
+ Simple things are done simply.
142
+
+ Supported by all major browsers and enabled by default.
143
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
90
144
```
91
145
在瀏覽器技術中,只有 JavaScript 能唯一滿足這三項。
92
146
93
147
這造就 JavaScript 如此獨特。這也是為什麼它是建立瀏覽器介面最為廣泛的工具。
94
148
149
+
<<<<<<< HEAD
95
150
此外,JavaScript 也可以建立伺服器和手機應用程式等等。
151
+
=======
152
+
That said, JavaScript can be used to create servers, mobile applications, etc.
-[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.
- 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.
Also, if you're developing for the browser, then there are other specifications covered in the [second part](info:browser-environment) of the tutorial.
-**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.
-<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.
若使用 Windows 系統,也可選用 "Visual Studio",但別跟 "Visual Studio Code" 搞混了。"Visual Studio" 是一個需付費且強大的 Windows 專屬編輯器,特別適合開發 .NET 平台,用來開發 JavaScript 也不錯。它有個免費的版本 [Visual Studio Community](https://www.visualstudio.com/vs/community/)。
-[Vim](https://www.vim.org/) and [Emacs](https://www.gnu.org/software/emacs/) are also cool if you know how to use them.
51
+
>>>>>>> 52c1e61915bc8970a950a3f59bd845827e49b4bf
39
52
40
53
## 不要起爭議
41
54
@@ -45,3 +58,12 @@
45
58
46
59
選擇編輯器就像選其他工具一樣,需要依照你的專案、習慣和個人喜好選擇。
47
60
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).
0 commit comments