简体   繁体   English

脚本语言和编译语言

[英]Scripting Language and Compiled Language

I have two questions: 我有两个问题:

  1. How does Jquery/ MooTools extend the syntax of Javascript? Jquery / MooTools如何扩展Javascript的语法? I mean why can you just have new syntax for Jquery and MooTools that does not exist in Javascript? 我的意思是为什么你只能为Jquery和MooTools提供Javascript中不存在的新语法?
  2. Since MooTools allows user to have class, inheritances. 由于MooTools允许用户拥有类,继承。 Interpreted language like this is getting closer to compiled language. 像这样的解释语言越来越接近编译语言。 Will they eventually replace Java (which runs on JVM)? 他们最终会取代Java(在JVM上运行)吗? Or are there specific aspects of Java that extension to Javascript will never achieve? 或者是否有Java的特定方面,Javascript的扩展永远不会实现?

It may be foolish questions but I really want some keywords to explain them. 这可能是愚蠢的问题,但我真的想要一些关键字来解释它们。

Thanks 谢谢

One way that JQuery gives the impression of redefining the language is with the $ operator. JQuery给出重新定义语言印象的一种方法是使用$运算符。 What may not be clear however is that $ is just a function declared at window (global) scope, since $ is a valid variable name in JavaScript: 然而,可能不太清楚的是,$只是在窗口(全局)范围内声明的函数,因为$是JavaScript中的有效变量名:

From the source: 从来源:

jQuery = window.jQuery = window.$ = function( selector, context ) {
    // The jQuery object is actually just the init constructor 'enhanced'
    return new jQuery.fn.init( selector, context );
},

They are not extending the syntax of javascript per say. 他们没有扩展javascript的语法。 They still have to abide by all the grammar rules of javascript. 他们仍然必须遵守javascript的所有语法规则。

jQuery does not extend the syntax of javascript - it only uses some fancy tricks like using the $ variable. jQuery没有扩展javascript的语法 - 它只使用一些花哨的技巧,比如使用$ variable。 MooTools' classes are in fact a class you instantiate. MooTools的类实际上是一个实例化的类。 Neither extend the syntax of javascript, only makes it appear so by clever use of variables. 既没有扩展javascript的语法,也只是通过巧妙地使用变量使它看起来如此。

As to your second question about interpreted and compiled languages, the answer is a bit more complicated and perhaps beyond my scope. 至于关于解释和编译语言的第二个问题,答案有点复杂,可能超出了我的范围。 Try Google . 试试谷歌

How does Jquery/ MoonTool extend the syntax of Javascript? Jquery / MoonTool如何扩展Javascript的语法? I mean why you can just have new syntax for Jquery and MoonTool that does not exist in Javascript? 我的意思是为什么你可以为Jquery和MoonTool提供Javascript中不存在的新语法?

You can't. 你不能。 Javascript syntax is just very flexible, so you there are a lot of ways you can add new semantics (meaning/functionality) to existing syntax. Javascript语法非常灵活,因此您可以通过很多方法为现有语法添加新语义(含义/功能)。

Since MoonTool allows user to have class, inheritances. 由于MoonTool允许用户拥有类,继承。 Interpreted language like this is getting closer to compiled language. 像这样的解释语言越来越接近编译语言。 Will they eventually replace Java (which runs on JVM)? 他们最终会取代Java(在JVM上运行)吗?

Interpreted vs. compiled has nothing to do with language syntax or semantics. 解释与编译与语言语法或语义无关。 Besides, both Javascript and Java are usually JIT-compiled these days. 此外,Javascript和Java现在通常都是JIT编译的。

Or are there specific aspects of Java that extension to Javascript will never achieve? 或者是否有Java的特定方面,Javascript的扩展永远不会实现?

Static type checking for one thing (unless, of course, the language spec is changed accordingly. But that's most likely not possible in a sane way). 静态类型检查一件事(当然,除非语言规范相应地改变。但这很可能不会以理智的方式)。 Or native support for normal ints. 或原生支持正常的整数。

Libraries like jQuery and MooTools don't "extend" the JavaScript syntax. 像jQuery和MooTools这样的库不会“扩展”JavaScript语法。 It's all legal JavaScript. 这都是合法的JavaScript。 They just use it in a way that you aren't familiar with. 他们只是以你不熟悉的方式使用它。 For example, $ in jQuery is just the name of a variable, since JavaScript variables can have $ in them. 例如,jQuery中的$只是变量的名称,因为JavaScript变量可以包含$

Also, no, JavaScript is a completely different animal than Java. 此外,不,JavaScript是一种完全不同于Java的动物。 JavaScript is an object oriented language, but it's done differently. JavaScript 一种面向对象的语言,但它的完成方式不同。 I'm not familiar with MooTools, but they don't do anything special. 我不熟悉MooTools,但他们没有做任何特别的事情。 It may seem like they are "changing" JavaScript, but they are not. 看起来他们正在“改变”JavaScript,但事实并非如此。 It just doesn't make sense to compile JavaScript. 编译JavaScript是没有意义的。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM