开发者

Scripting Language and Compiled Language

开发者 https://www.devze.com 2023-02-21 08:03 出处:网络
I have two questions: How does Jquery/ MooTools extend the syntax of Javascript? I mean why can you just have new syntax for Jquery and MooTools that does not exist in Javascript?

I have two questions:

  1. How does Jquery/ MooTools extend the syntax of Javascript? I mean why can you just have new syntax for Jquery and MooTools that does not exist in Javascript?
  2. Since MooTools allows user to have class, inheritances. Interpreted language like this is getting closer to compiled language. Will they eventually 开发者_C百科replace Java (which runs on JVM)? Or are there specific aspects of Java that extension to Javascript will never achieve?

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. 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:

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. They still have to abide by all the grammar rules of javascript.


jQuery does not extend the syntax of javascript - it only uses some fancy tricks like using the $ variable. MooTools' classes are in fact a class you instantiate. Neither extend the syntax of javascript, only makes it appear so by clever use of variables.

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? I mean why you can just have new syntax for Jquery and MoonTool that does not exist in 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.

Since MoonTool allows user to have class, inheritances. Interpreted language like this is getting closer to compiled language. Will they eventually replace Java (which runs on JVM)?

Interpreted vs. compiled has nothing to do with language syntax or semantics. Besides, both Javascript and Java are usually JIT-compiled these days.

Or are there specific aspects of Java that extension to Javascript will never achieve?

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. It's all legal 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.

Also, no, JavaScript is a completely different animal than Java. JavaScript is an object oriented language, but it's done differently. I'm not familiar with MooTools, but they don't do anything special. It may seem like they are "changing" JavaScript, but they are not. It just doesn't make sense to compile JavaScript.

0

精彩评论

暂无评论...
验证码 换一张
取 消