简体   繁体   中英

Can IE interpret both JScript and JavaScript?

The window.setTimeout reference for IE states that setTimeout has an optional third parameter defining the language.

The possible languages are JScript, VBScript and JavaScript.

I already know IE can parse VBScript but

How does IE parse JavaScript differently from JScript?

Personally I thought the dialect of EcmaScript that IE parsers and runs was called JScript.

[ Edit ]

As mentioned by people it appears that Microsoft labels their ES3 engine as "JScript" and their ES5 engine as "JavaScript". The ES5 engine is in IE9.

Can we use their ES3 engine in IE9 by passing in "JScript" to setTimeout ?

Personally I thought the dialect of EcmaScript that IE parsers and runs was called JScript.

It is. The "JScript" and "JavaScript" values for the third parameter are just synonyms. I can't find a reference for it, but you can be quite certain IE doesn't have two separate interpreters lying around, one that has JScript-isms and one that doesn't.

And here's the proof: If you run this in IE9 ( live copy ):

HTML:

<input type='button' id='btnJScript' value='JScript'>
<input type='button' id='btnJavaScript' value='JavaScript'>

JavaScript:

window.onload = function() {

  document.getElementById('btnJScript').onclick = function() {
    testIt("JScript");
  };
  document.getElementById('btnJavaScript').onclick = function() {
    testIt("JavaScript");
  };

  function testIt(lang) {
    var s = "var a = [1, 2, ]; display(a.length);";
    display("Calling <code>setTimeout</code> with <code>'" +
            s + "', 0, '" + lang + "'</code>");
    setTimeout(s, 0,lang);
  }
};

function display(msg) {
  var p = document.createElement('p');
  p.innerHTML = msg;
  document.body.appendChild(p);
}

In both cases, you get the output "2" displayed by the eval'd setTimeout string. But in JScript, even the most recent version in IE8, that trailing comma would mean the array had three entries, not two. Details on that here. Thus, IE9 is using its latest interpreter in both cases, not downshifting to "JScript" in some way if you pass "JScript" as the third parameter.

Update : And similarly (I just fired up my IE8 box), if you run this on IE8 you get "3" in both cases.

From this MSDN page , you can see that JScript is Microsoft's name for its implementation of ECMAScript 3, whereas JavaScript is its name for the implementation of ECMAScript 5 that appears in IE9.

I guess the best answer I could give, somebody else already did.

Well known, Mr. Resig in person: http://ejohn.org/blog/versions-of-javascript/

snippet

  • IE 6-7 support JScript 5 (which is equivalent to ECMAScript 3, JavaScript 1.5)
  • IE 8 supports JScript 6 (which is equivalent to ECMAScript 3, JavaScript 1.5 – more bug fixes over JScript 5)
  • Firefox 1.0 supports JavaScript 1.5 (ECMAScript 3 equivalent)
  • Firefox 1.5 supports JavaScript 1.6 (1.5 + Array Extras + E4X + misc.)
  • Firefox 2.0 supports JavaScript 1.7 (1.6 + Generator + Iterators + let + misc.)
  • Firefox 3.0 supports JavaScript 1.8 (1.7 + Generator Expressions + Expression Closures + misc.)
  • The next version of Firefox will support JavaScript 1.9 (1.8 + To be determined)
  • Opera supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.
  • Safari supports a language that is equivalent to ECMAScript 3 + Getters and Setters + misc.

I guess IE9's JScript engine ( Chakra ) comes as close as possible to "Javascript". However, it supports many features of ES5. See " IE9 Javascript engine ". So we probably could extend the above list with

  • IE9 supports JScript 9 (which is equivalent to ECMAScript 5, JavaScript 1.8.5)

You can safely think that JScript is the same as JavaScript and you won't bump into any problems.

http://en.wikipedia.org/wiki/JScript#Comparison_to_JavaScript

JScript and Javascript are the same things in IE. JScript was renamed to JavaScript in IE9 because of more standard (or better, more interoperable) implementation.

The manual page you've referenced states that sLanguage is a parameter which can take the values VBScript , JScript , or Javascript .

It isn't that JScript is different from Javascript, it's just that both are valid names for the same language, they need to support both names.

JScript was Microsoft's name for their reverse-engineered clone of Javascript. The languages have now been merged by the standardisation work of the ECMA resulting in EcmaScript, although it is still generally referred to as Javascript.

But Microsoft needs to support both names because they want to retain compatiblity with old code written for ancient versions of IE which still uses the old JScript name.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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