当前位置:网站首页>HTNL introduction
HTNL introduction
2022-06-28 17:49:00 【Hua Weiyun】
Let's see JavaScript What's special , What can we do with it , And what other technologies can work with it .
What is? JavaScript?

JavaScript Originally created for “ Make the web page more vivid ”.
The program written in this programming language is called Script . They can be written directly on the page HTML in , Automatically execute when the page is loaded .
Scripts are provided and executed in plain text . They don't need special preparation or compilation to run .
This aspect ,JavaScript and Java There's a big difference .
Why call JavaScript?
JavaScript When it was first born , Its name is “LiveScript”. But because at that time Java Is very popular , So I decided to position a new language as Java Of “ Younger brother ” It will help its popularity .
With JavaScript The development of , It has become a completely independent language , And also has its own language norms ECMAScript. Now? , It and Java There is no relationship between .
Now ,JavaScript Not only in the browser , It can also be executed on the server , It can even be carried anywhere JavaScript engine Executed in the device .
Embedded in the browser JavaScript engine , Sometimes called “JavaScript virtual machine ”.
Different engines have different “ Code name ”, for example :
- V8) —— Chrome、Opera and Edge Medium JavaScript engine .
- SpiderMonkey —— Firefox Medium JavaScript engine .
- …… There are other codes , image “Chakra” be used for IE,“JavaScriptCore”、“Nitro” and “SquirrelFish” be used for Safari, wait .
These terms are easy to remember , Because they often appear in developer articles . We also use these terms . for example , If “V8 Support a function ”, So we can think that this function can be in Chrome、Opera and Edge Normal operation in .
How the engine works ?
The engine is complicated , But the fundamentals are simple .
- engine ( If it's a browser , Then the engine is embedded ) Read (“ analysis ”) Script .
- then , The engine transforms the script into (“ compile ”) For machine language .
- then , Machine code executes quickly .
The engine optimizes every stage of the process . It can even monitor compiled scripts as they run , Analyze the data flowing through the script , And further optimize the machine code according to the obtained information .
In the browser JavaScript What can be done ?
modern JavaScript It's a kind of “ Safe ” programing language . It does not provide for memory or CPU Bottom level access to , Because it was originally created for browsers , You don't need these functions .
JavaScript The ability of the depends largely on the environment in which it operates . for example ,Node.js Support allows JavaScript Read / Write to any file , Functions that execute network requests, etc .
In the browser JavaScript Can do with webpage operation 、 User interaction and Web Everything about servers .
for example , In the browser JavaScript You can do the following :
- Add a new HTML, Modify the existing content of the web page and the style of the web page .
- Respond to user behavior , Respond to mouse clicks , The movement of the pointer , Key press .
- Send network requests to remote servers , Download and upload files ( So-called AJAX) and [COMET]
- Get or set cookie, Ask questions or send messages to visitors .
- Remember the client's data (“ The local store ”).
In the browser JavaScript Nothing to do ?
For users ( Information ) Security , In the browser JavaScript My ability is limited . The purpose is to prevent malicious web pages from obtaining users' private information or damaging users' data .
Examples of such restrictions include :
In the web page JavaScript Cannot read 、 Write 、 Copy and execute any file on the hard disk . It doesn't have direct access to the operating system functions .
Modern browsers allow JavaScript Do some file related operations , But this operation is limited . Only if the user makes a specific behavior ,JavaScript To operate this file . for example , The user puts the file “ Drag and drop ” Go to browser , Or by
<input>The tag selects the file .There are many with cameras / How the microphone interacts with other devices , But these all need the explicit permission of the user . therefore , To enable the JavaScript The web page should not be secretly activated by webcam to watch you , And send your message to National security agency .
Different tabs / Windows usually don't know each other . occasionally , There will also be some connections , For example, a tab passes through JavaScript Open another tab . But even in this case , If two tabs don't open the same website ( domain name 、 Any website with different protocol or port ), They can't communicate with each other .
That's what's called “ The same-origin policy ”. In order to solve “ The same-origin policy ” problem , Both tabs must be all Contains some specific... That deal with this problem JavaScript Code , And all allow data exchange . This tutorial will cover this part of related knowledge .
This restriction is also for the information security of users . for example , User opened
http://anysite.comWeb pages must not be accessiblehttp://gmail.com( Another tab opens the page ) You can't steal information from there .JavaScript You can easily communicate with the server where the current page is located through the Internet . But from other sites / The ability to receive data in the domain's servers is weakened . Even though you can , But you need a clear protocol from the remote server ( stay HTTP header in ). This is also for the information security of users .
If you are outside the browser environment ( For example, on the server ) Use JavaScript, There is no such restriction . Modern browsers also allow you to install plug-ins that may require extended permissions / Expand .
What makes JavaScript different ?
There are at least 3 One thing is worth mentioning :
- And HTML/CSS Fully integrated .
- Simple things , Simply do it .
- Supported by all major browsers , And on by default .
JavaScript Is the only browser technology that combines these three things .
That's why JavaScript different . This is why it is the most widely used tool for creating browser interfaces .
Besides ,JavaScript It can also be used to create server and mobile applications .
JavaScript “ The upper ” Language
Different people want different functions .JavaScript The grammar of can't meet everyone's needs .
This is normal , Because everyone's projects and needs are different .
therefore , Many new languages have emerged recently , Before these languages are executed in the browser , Will be compile ( conversion ) become JavaScript.
Modern tools make compilation very fast and transparent , In fact, developers are allowed to write code in another language and will “ Automatic conversion ” by JavaScript.
Examples of such languages are :
- CoffeeScript yes JavaScript A kind of grammar sugar . It introduces a shorter Syntax , So that we can write more clear and concise code . Usually ,Ruby Developers love it .
- TypeScript Focus on adding “ Strict data types ” To simplify development , To better support the development of complex systems . Developed by Microsoft .
- Flow Also added data types , But in a different way . from Facebook Development .
- Dart It's an independent language . It has its own engine , The engine can run in a non browser environment ( For example, mobile applications ), It can also be compiled into JavaScript. from Google Development .
- Brython It's a Python To JavaScript The translator of , Let's not use JavaScript Under the circumstances , To be pure Python Write applications .
- Kotlin It's a modern 、 A simple and secure programming language , The application can be written in the browser and Node Running in the environment .
There are many such languages . Of course , Even if we are using such a compilation language , We also need to understand JavaScript. Because I understand JavaScript So that we can really understand what we are doing .
summary
- JavaScript At first, it was a language specially designed for browsers , But now it's also used in many other environments .
- JavaScript As the most widely used browser language , And with the HTML/CSS Fully integrated , Have a unique position .
- There are many other languages that can be “ compile ” become JavaScript, These languages also provide more functions . It's best to understand these languages , At least I have mastered JavaScript Then we'll have a general understanding of .
边栏推荐
- Idea of capturing mobile terminal variant combination
- [dark horse morning post] Tencent responded that a large number of users' QQ numbers were stolen; Weiya's husband company was fined 190000 yuan; China Evergrande is applied for liquidation; Guanxiaoto
- CSDN Blogger
- 此虚拟机的处理器所支持的功能不同于保存虚拟机状态的虚拟机的处理器所支持的功能
- The fourth largest operator cannot be a "catfish"
- Does the dataworks SQL script support if else judgment of statement blocks
- Sum of factor numbers of interval product
- 节点基础~节点层级
- 数据源只能连阿里云的云数据库吗?阿里云服务器里装的数据库连不上嘛?
- Visubit "ai+3d vision" product series | loading assembly workstation
猜你喜欢

2022 operation of simulated examination platform of hoisting machinery command examination question bank

Problems encountered in local deployment conflict: MySQL database code, isolation level and verification code are not displayed

Win10 compiles curl library source code with cmake3.22 and vs2019 and calls

rsync 远程同步(日落尤其温柔的人间皆是浪漫)

Use PEGA to develop a simple RPA program

2022年化工自动化控制仪表考试模拟100题模拟考试平台操作
Tidb v6.0.0 (DMR): initial test of cache table - tidb Book rush

Flutter tips: mediaquery and build optimization secrets you don't know

Stackoverflow 2022 developer report: PostgreSQL surpasses MySQL!

第四个专栏,Kubernetes云原生实战,它来了~
随机推荐
11 effective ways to enhance WordPress
Visio use
Google launches advanced API security to protect APIs from security threats
2022 practice questions and mock examination of Shandong Province safety officer C certificate examination
MySQL high availability MHA (accidentally passed my youth)
jq插件分析啊啊
Node foundation ~ node level
[question skimming diary] and a subarray of K
问下 flink sql cdc. 能同步多张表然后sink到一份表中么 同步的表通过 joi
Discrete mathematics single shot, full shot and double shot
2022危险化学品生产单位安全生产管理人员复习题及答案
通达信能开户炒股吗?安全吗?
Redis principle - hash
Why insert is configured with'select last_ INSERT_ What if id() 'returns 0?
Is the account opening link given by CICC securities manager safe? Who can I open an account with?
dataworks SQL脚本支持语句块的if else 判断吗
MCU modifies network hardware driver (PHY chip replacement)
How to configure the Oracle CDC service name without Sid?
Redis 原理 - Hash
2022年山东省安全员C证考试练习题及模拟考试