最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

internet explorer - Can IE interpret both JScript and JavaScript? - Stack Overflow

programmeradmin2浏览0评论

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 ?

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 ?

Share Improve this question edited Jul 22, 2011 at 14:01 Raynos asked Jul 22, 2011 at 13:49 RaynosRaynos 169k57 gold badges357 silver badges398 bronze badges 3
  • This question strikes me as being equivalent to asking whether Chrome can run 'V8 Scripts' but maybe I'm just confused by Microsoft's oddball terminology – dtanders Commented Jul 22, 2011 at 14:02
  • @dtanders I interpret JavaScript as the Mozilla implementation of the ES engine. There might have been a chance that IE secretly has an extra interpreter hidden in it. – Raynos Commented Jul 22, 2011 at 14:06
  • @dtanders: If you look at the MSDN link, it really does list "JScript" and "JavaScript" separately, and nowhere on the page does it say they're synonyms (which is just par for the course with MSDN documentation, in my experience; spotty doesn't half say it). – T.J. Crowder Commented Jul 22, 2011 at 14:21
Add a ment  | 

6 Answers 6

Reset to default 6

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 ma 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/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) es 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/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 patiblity with old code written for ancient versions of IE which still uses the old JScript name.

发布评论

评论列表(0)

  1. 暂无评论