ADM-201 dump PMP dumps pdf SSCP exam materials CBAP exam sample questions

《网络忍者NodeJS入门》#3 介绍V8 JavaScript引擎 – 译学馆
未登陆,请登陆后再发表信息
最新评论 (0)
播放视频

《网络忍者NodeJS入门》#3 介绍V8 JavaScript引擎

Node JS Tutorial for Beginners #3 - The V8 Engine

同学们好 欢迎来到第三节Node.js课程
Yo, what’s up today guys, welcome to your third Node.js tutorial,
本视频我将讲一点V8引擎
and in this video I’m going to talk a little bit about the V8 engine.
[开场音乐]
[intro music]
好了 为了我们能充分理解Node.js是怎么工作的
Alright then, so we can fully understand how Node.js works.
我想讲的更深入一点
I want to dive under the hood a little bit,
讲一讲构成Node.js的不同的组件
and talk about the different components that it’s made from.
第一个就是V8引擎
And the first one is the V8 engine.
其实 V8 JavaScript 引擎就是Node.js的心脏
Now, the V8 JavaScript engine is at the heart of Node.js,
所以我真心觉得花点时间了解它
so I do think it’s worthwhile knowing a little bit about it,
和它是怎么工作的是值得的
and how it works.
所以 首先 什么是一个JavaScript 引擎
So first of all, what is a JavaScript engine?
当我们写 JavaScript 的时候
So, when we write JavaScript,
电脑它自己是无法理解的
the computer itself does not understand it.
它用一个JavaScript引擎
It takes a JavaScript engine,
将JavaScript代码转为机器代码
to convert that JavaScript code into machine code,
即是机器能理解的东西 这样电脑可以处理它
something that the computer can understand, so that it can be processed.
理解了吗?
Ok? So,
就像这样
it looks something like this.
我们有机器码 在这儿 在栈的底部
We have machine code, right here, at the bottom of the stack.
这就是电脑运行的东西
And that is what computers run on,
即是它们能理解的
it’s what they understand.
但是 用机器码来编写程序是非常困难的
But it’s very difficult to program in machine code,
它看起来非常凌乱 你不知道会发生什么
it looks an absolute messy, you don’t know what’s going on.
所以我们开始用一种不同的语言把它抽象出来
So then we started to abstract away from it using different languages.
我们就有了汇编语言
We have assembly language,
就是在”Machine Code”上面那个 但是它仍然非常像机器码
which sits just above it, but still very much like machine code.
于是我们就有了像C++或者C这样的语言
Then we have something like C++ or C,
这些语言真的非常流行 因为它们相当抽象
and these are really popular because they abstract away quite a lot,
但是它们仍然遗留了很多问题
but they still remain a lot of power.
最后我们就有了JavaScript这样的语言
And then final we have things like JavaScript,
它们位于堆的顶部
which sit at the…the top of the pile,
对于机器码来说已经非常抽象
and abstracted a lot away from machine code.
所以
So,
当我们写JavaScript的时候
when we write in JavaScript,
我们需要一种方式来把它转为机器码
we need a way for it to be converted into machine code,
让电脑理解我们想让它做什么
for it to understand what we want it to do.
Node.js其实是用C++写的
So, Node.js itself is actually written in C++.
咋一听这里说的可能有点偏题
Which might seem a little bit off the wall at first,
因为目前全都是关于写JavaScript
since it’s all about writing in JavaScript.
但是这里的不同之处是
But here’s the distinction,
Node.js自身通过C++编写
Node.js itself is written in C++,
但是作为一个程序 它允许我们可以写
but as a programme, it allows us to write JavaScript,
运行在电脑和服务器上的JavaScript
which can run on a computer or server.
理解否?
Ok?
Node.js通过C++编写的原因是
And the reason that Node.js is written in C++,
它使用了谷歌创造的V8 JavaScript引擎
is because it uses the V8 JavaScript engine created by Google,
它同样也是通过C++编写的
which is also written in C++.
那么 我们已经知道Node.js通过C++编写
So, we know that Node.js is written in C++.
同时我们也知道
And we also know that,
Node.js的心脏是V8 JavaScript引擎
at the heart of Node.js is the V8 JavaScript engine,
用来转换我们编写的JavaScript代码
which converts the JavaScript that we write,
变成机器码从而让机器能够理解
into code that the machines understand, machine code.
如果你想多了解一些V8引擎
So if you do want to read a little bit more about V8,
那么你可以到’developers.google.com/v8’网站
then you can come to the ‘developers.google.com’ website, ‘/v8’.
你可以看到这写着
And you can see here it says that,
V8 是谷歌的开源高性能JavaScript引擎
V8 is Google’s open source high-performance JavaScript engine,
通过C++编写
written in C++,
被用在 Google Chrome中
and used in Google Chrome.
所以它也是一个运行在 Google Chrome中的 JavaScript引擎
So it’s also the JavaScript engine that’s ran in Google Chrome.
所以当我们在 Google Chrome这个浏览器中创建JavaScript时
So when we create JavaScript in Google Chrome, in the browser,
那么V8就被用来翻译它
then V8 is used at that point too, to translate it.
理解?
Ok?
那可以来到下面看看 你可以看到这写着
And you’ll see down here, that you can see it says,
它可以单独运行 或被嵌入到任何C++应用
It can run standalone, or be embedded into any C++ application.
所以我们知道Node.js是一个C++应用
So we know that Node.js is a C++ application,
它所做的就是把V8
and what it does is take V8,
嵌入到Node.js
and it embeds it indo Node.js.
那么 Node.js是怎么与V8工作的
So, how does Node.js work with V8?
Node.js是用C++编写的 对吧?
Node.js is witten in C++, right?
V8 被嵌入到这儿
And V8 is embedded into it, right there.
所以当我们写JavaScript的时候
So when we write JavaScript,
JavaScript通过Node.js
and we route through Node.js,
被传入V8引擎
it’s passed into V8,
然后被转为电脑能理解的机器码
and converted into machine code which the computer can understand.
V8是Node.js核心的一部分
Now V8 is just a part of the Node.js C++ core.
Node.js的其他的部分也是通过C++编写的
And there’s other parts of Node.js written in C++ too,
那么 它们做了什么
so what do they do?

Well,
Node.js中部分代码钩入JavaScript V8 引擎
the rest of the C++ in Node.js hooks into the JavaScript V8 engine,
并且向它增加了其他的功能
and it adds additional features to it.
所以 在一开始
So initially,
JavaScript之前是被设计运行在浏览器中
JavaScript was designed to run in a browser,
而不是用来处理底层操作的
and it wasn’t meant to deal with lower level operations.
但是C++.. 不好意思
But C++ was…was, sorry.
它远比JavaScript强大
So it’s far more powerful than JavaScript.
所以 Node.js 通过C++编写
So Node.js, which is written in C++,
钩入V8引擎
hooks into the V8 engine.
并且以传入这些特性的方式
And it extends it, in such a way,
来扩展JavaScript引擎
that passes on these additional features to JavaScript,
例如 读取正确的文件
such as, reading the right files,
或者是连接数据库
or connecting to a database.
这就是为什么Node.js让人如此激动的原因
So this is what makes Node.js so, so exciting.
事实上 我们已经给于JavaScript远比之前
The fact that we now have been given much greater power with JavaScript,
更加强大的功能
that we didn’t have before.
因此 它可以让我们用JavaScript编写服务侧代码
And therefore it enables us to create server-side code in JavaScript,
这真的很酷
which is really cool.
那么
So,
我想我已经给了你
I think that’ll do now for V8.
大概的V8背景和它所起的作用
Eh, gives you a kind of…a rough background of what it does,
以及Node.js是怎么工作的
and how Node.js works.
有问题吗? 请写在下面
Any question, drop those down below.
好了 同学们 下节课见
Otherwise guys, I’m going to see you in the very next tutorial.

发表评论

译制信息
视频概述

本届视频讲述了Node.js的核心是什么和为什么它能运行在服务器上

听录译者

positiveme

翻译译者

【B】Cod

审核员

知易行难

视频来源

https://www.youtube.com/watch?v=86tgU7UaJmU

相关推荐