什么是“原生 JavaScript”?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7022007/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
What is "native JavaScript"?
提问by NsM
Is there anything called "Native JavaScript"? I have seen this term in a job description I am going to be interviewing.
有没有叫做“原生 JavaScript”的东西?我在我将要面试的职位描述中看到了这个词。
Is regular JavaScript is same as Native JavaScript?
常规 JavaScript 与 Native JavaScript 相同吗?
回答by Ray Toal
The term "native" is very overused in JavaScript.
术语“原生”在 JavaScript 中被过度使用。
Colloquially, it is used as in Johan's answer: no JQuery, Moo, Dojo.
Analogous to the JNI for Java, Google's GWT and similar I-compile-down-to-JavaScript talks about the underlying implementation as being native.
The originaluse of native in JS, I believe, refers to objects built and defined in ECMAScript as opposed to the environment. JavaScript, as an ECMAScript language, is not intended to be self-sufficient; it is embedded in a host environment such as a Web browser, Photoshop, Acroread, etc. When you write a web client program, you will use objects such as
Math
,Function
,Array
,Window
, andButton
. The first three are native(independent of host environment), while the last two are non-native (supplied by the host environment). This is kind of the opposite of cdhowie's answer, which is a good answer BTW. Just interesting, though!
通俗地说,它在 Johan 的回答中使用:没有 JQuery、Moo、Dojo。
类似于 Java 的 JNI,Google 的 GWT 和类似的 I-compile-down-to-JavaScript 将底层实现视为本机。
我相信,JS中原生的原始用法是指在 ECMAScript 中构建和定义的对象,而不是环境。JavaScript 作为一种 ECMAScript 语言,并不打算自给自足;它被嵌入在一个主机环境,如Web浏览器,Photoshop中,Acroread等。当你写一个Web客户端程序,你将使用对象,如
Math
,Function
,Array
,Window
,和Button
。前三个是原生的(独立于宿主环境),而后两个是非原生的(由宿主环境提供)。这与 cdhowie 的回答正好相反,顺便说一句,这是一个很好的回答。不过很有趣!
I'm sure there are other interpretations. My guess is that if you see this in a job description, it's probably not the last one: that definition is too academic. :)
我相信还有其他解释。我的猜测是,如果你在工作描述中看到这一点,它可能不是最后一个:这个定义太学术了。:)
Here is the official definition from the ECMAScript-262 Standard, Fifth Edition:
以下是 ECMAScript-262 标准第五版的官方定义:
4.3.6 native object --- object in an ECMAScript implementation
whose semantics are fully defined by this specification rather
than by the host environment. NOTE Standard native objects are
defined in this specification. Some native objects are built-in;
others may be constructed during the course of execution of an
ECMAScript program.
In other words the built-ins like Math
, Object
, String
, RegExp
are native, as are any objects I make with object literals or function definitions. But host objectsare the opposite. Sorry for the ramble.
换句话说,像Math
, Object
, String
, 之类的内置RegExp
函数是本机的,就像我使用对象文字或函数定义创建的任何对象一样。但宿主对象正好相反。抱歉乱跑了。
回答by degr
Native JS, I think, it's example below:
我认为本机 JS 是下面的示例:
$=~[];$={___:++$,$$$$:(![]+"")[$],__$:++$,$_$_:(![]+"")[$],_$_:++$,$_$$:
({}+"")[$],$$_$:($[$]+"")[$],_$$:++$,$$$_:(!""+"")[$],$__:++$,$_$:
++$,$$__:({}+"")[$],$$_:++$,$$$:++$,$___:++$,$__$:++$};$.$_=
($.$_=$+"")[$.$_$]+($._$=$.$_[$.__$])+($.$$=($.$+"")[$.__$])+
((!$)+"")[$._$$]+($.__=$.$_[$.$$_])+($.$=(!""+"")[$.__$])+
($._=(!""+"")[$._$_])+$.$_[$.$_$]+$.__+$._$+$.$;$.$$=$.$+
(!""+"")[$._$$]+$.__+$._+$.$+$.$$;$.$=($.___)[$.$_][$.$_];
$.$($.$($.$$+"\""+$.$$_$+$._$+$.$$__+$._+"\"+$.__$+$.$_$+$.$_$+
$.$$$_+"\"+$.__$+$.$_$+$.$$_+$.__+".\"+$.__$+$.$$_+$.$$$+
"\"+$.__$+$.$$_+$._$_+"\"+$.__$+$.$_$+$.__$+$.__+$.$$$_+
"(\\"\"+$.__$+$.__$+$.___+$.$$$_+(![]+"")[$._$_]+(![]+"")[$._$_]+
$._$+", \"+$.__$+$.$$_+$.$$$+$._$+"\"+$.__$+$.$$_+$._$_+
(![]+"")[$._$_]+$.$$_$+"!\\")\"+$.$$$+$._$$+"\"")())();
回答by Jhankar Mahbub
Native JavaScript is the JavaScript implemented in the browser.
Native JavaScript 是在浏览器中实现的 JavaScript。
Browser implementation is followed by ECMA standard and some extra method. For example, if you familiar with jQuery and want to select element by ID
浏览器实现之后是 ECMA 标准和一些额外的方法。例如,如果您熟悉 jQuery 并希望通过 ID 选择元素
$('#myId')
Native JavaScript will be
原生 JavaScript 将是
document.getElementById('myId')
Now, if you need to do some simple tasks. You might not or should not load a huge jQuery Library and execute all its functionality. Rather 10 lines of native Javascript will do the job instead of 5 lines of jQuery code
现在,如果您需要执行一些简单的任务。您可能不会或不应该加载庞大的 jQuery 库并执行其所有功能。而是 10 行原生 Javascript 将完成这项工作,而不是 5 行 jQuery 代码
回答by scunliffe
Not to complicate things too much more as @Ray's answer is correct, but a new JavaScript framework for building mobile applications has emerged called NativeScripthttps://www.nativescript.org/If not confusing enough, this framework allows you to write pure "vanilla" JavaScript, but call Native (iOS/Android/WindowsPhone) APIs.
不要把事情复杂化太多,因为@Ray的答案是正确的,但是已经出现了一个用于构建移动应用程序的新 JavaScript 框架,称为NativeScript https://www.nativescript.org/如果还不够混乱,这个框架允许您编写纯“ vanilla" JavaScript,但调用本机 (iOS/Android/WindowsPhone) API。
It is almost like writing a "Native" app (think Objective-C/Java/C#) but using a single language (JavaScript) which is interpretedat run-time on the device.
这几乎就像编写“本机”应用程序(想想 Objective-C/Java/C#),但使用的是在设备运行时解释的单一语言 (JavaScript) 。
I suspect as this library's popularity grows "Native JavaScript" may be used as a label to describe code using this framework (esp. since that's how I got to this question via Google)
我怀疑随着这个库的流行度的增长,“Native JavaScript”可能会被用作描述使用这个框架的代码的标签(特别是因为这就是我通过谷歌得到这个问题的方式)
回答by Johan
I belief native Javascript reveres to 'vanilla' javascript, so no jQuery, MooTools, etc. Just plain old javascript
我相信原生 Javascript 崇尚 'vanilla' javascript,所以没有 jQuery、MooTools 等。只是普通的旧 javascript
回答by user4447835
Native JavaScript is all JavaScript code . Not any kind of framework codes. It's faster and loads in the browser. You can use for simple browser task, that does not require any database interface, or any back-end large computation work. Using framework makes codes larger and makes browser slow.
本机 JavaScript 是所有 JavaScript 代码。不是任何类型的框架代码。它更快并且可以在浏览器中加载。您可以用于简单的浏览器任务,不需要任何数据库接口,或任何后端大型计算工作。使用框架会使代码变大并使浏览器变慢。
回答by Toby Allen
It is the same, perhaps just wondering if you've done more than just jayesh etc.
是一样的,也许只是想知道你是否做了不仅仅是 jayesh 等。
回答by cdhowie
The only context I know for the term "native JavaScript" involves writing JavaScript objects and/or functions that are implemented by the JavaScript provider and not written in JavaScript itself. For example, many of the functions you call on the window
object are implemented by the browser in its native language (C++ for Firefox/Mozilla, etc.). This mightbe what they mean...
我所知道的术语“原生 JavaScript”的唯一上下文涉及编写 JavaScript 对象和/或函数,这些对象和/或函数由 JavaScript 提供程序实现,而不是用 JavaScript 本身编写。例如,您在window
对象上调用的许多函数是由浏览器以其本机语言(Firefox/Mozilla 的 C++ 等)实现的。这可能是他们的意思......
They might also mean vanilla/pure JavaScript (without frameworks like jQuery or Prototype). Consider contacting them and asking for clarification.
它们也可能意味着 vanilla/pure JavaScript(没有像 jQuery 或 Prototype 这样的框架)。考虑联系他们并要求澄清。
回答by amal
No , Native Javascript to me means 3rd party js functions that can do things that regular js cant , kind of like the Java-JNI relationship . Google JNEXT and JSNI for more info.
不,原生 Javascript 对我来说意味着 3rd 方 js 函数,它可以做普通 js 不能做的事情,有点像 Java-JNI 关系。谷歌 JNEXT 和 JSNI 了解更多信息。
Again , I do not know the real context of the question , If i were you , I'd ask for clarification.
同样,我不知道问题的真实背景,如果我是你,我会要求澄清。