8

I have been using JavaScript in Windows Scripting, both in .JS files and .WSF files, for several years, but I have found that there are some methods that are not recognized when I put them in a script that is executed outside a web page that are valid in a script on a web page. I know that different browsers support different versions of JavaScript, and MSDN has a page that describes which functions and methods are supported in which Internet Explorer and Edge browser versions:

https://learn.microsoft.com/en-us/scripting/javascript/reference/javascript-version-information

but it does not say which methods are supported in Windows Scripting.

Does the version of JavaScript supported in Windows Scripting depend on the version of Windows, the version of Internet Explorer installed on the computer, or some other factor or combination of factors? Is there a way inside the JavaScript program to detect which version of JavaScript is being used as it is executed?

user692942
  • 16,398
  • 7
  • 76
  • 175
JDMorganArkansas
  • 123
  • 2
  • 10
  • Did you try to implement some kind of feature detection in Windows Scripting? Not sure why you need the JavaScript version. – Jeroen Heier Oct 12 '17 at 18:07
  • It’s not actually JavaScript, it’s Microsofts implementation called [tag:jscript]. – user692942 Oct 12 '17 at 19:05
  • I am aware of the fact that the Microsoft implementation of ECMAScript is sometimes called JScript, but MSDN and many other parts of Microsoft documentation use the terms JScript and JavaScript interchangeably. The question is how to determine which features of ECMAScript are supported when using Windows Scripting Host for .JS source files and JScript sections in a .WSF. Microsoft documentation does not explain this. The link in my post above tells what features are in IE6, IE7, IE8, IE9, IE10, IE11, Edge, and Windows Store apps. It does not mention Windows Scripting Host. – JDMorganArkansas Oct 12 '17 at 20:43
  • What originally prompted my asking this question was when I tried to use the method Date.now() in a standalone (non-HTML) .JS file. Microsoft documentation says that it is supported in IE9-IE11, Edge, and Windows Store apps. It is not supported in IE6, IE7, IE8, or whatever "Quirks" is. It apparently is NOT supported in Windows Scripting Host running on a 64-bit Windows 7 computer even though it DOES run in a .JS script in a HTML file in IE11 on the same computer. I wanted to know what other features of ECMAScript are or are not supported in Windows Scripting Host and what determines it. – JDMorganArkansas Oct 12 '17 at 21:41
  • @JDMorganArkansas that's because in Standards browser *(including Edge)* JavaScript is the defacto choice and JScript and by extension VBScript are slowly being swept under the carpet. The WSH is just another host like IE is a host the feature set is the same, so if it says *"only supported in Internet Explorer"* you safely use it in WSH. – user692942 Oct 12 '17 at 21:43
  • According to Wikipedia, Windows 7 runs WSH Version 5.8 as do Windows Server 2008 R2, Windows 8, and Windows Server 2012, but Windows 10 and Windows Server 2016 run WSH Version 5.812. Is there any documentation on what features of ECMAScript are supported in different versions of WSH? – JDMorganArkansas Oct 12 '17 at 21:44
  • @JDMorganArkansas According to [Wikipedia](https://en.wikipedia.org/wiki/ECMAScript) JScript 9.0 is based on ECMAScript 5.1 *(seens high to me)*. That's the best you are going to get I'm afraid, I've tried researching this before and not got much further than this. My advice would be stick to the JScript documentation, if you can still find it. – user692942 Oct 12 '17 at 21:52
  • For example, Date.now() works in a .JS script called by an HTML page displayed in Internet Explorer 11 on a Windows 7 computer, but it does NOT work in a .JS script run in WSH on the same computer. – JDMorganArkansas Oct 12 '17 at 22:04
  • @JDMorganArkansas I'm pretty sure I already explained this. JScript needs a host be it WSH, IE, Classic ASP it doesn't matter it can't function without one. In a modern "Standards" browser like Edge it is not supported unless run in quirks mode *(another name for IE legacy rendering engine)*, similarily in IE 11 it works until you are running in "Standards" mode *(this was the time when Microsoft started to move away from their none standard approach to browser rendering)*. – user692942 Oct 12 '17 at 22:16
  • @JDMorganArkansas Here is a copy of the [JScript Language reference *(via archive.org before Microsoft nuked it)*](https://web.archive.org/web/20110223213002/http://msdn.microsoft.com:80/en-us/library/yek4tbz0(v=vs.85).aspx). – user692942 Oct 12 '17 at 22:17
  • @JDMorganArkansas In relation to the `Date.now()` query, according to [MDN web docs](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Date/now) it *"method was standardized in ECMA-262 5th edition"* which might explain its absence from [JScript which was originally based on ECMA-262 3rd edition](https://msdn.microsoft.com/en-us/library/hbxc2t98(v=vs.85).aspx). The docs do provide a workaround in the form of a shim for `Date.getTime()` though. – user692942 Oct 12 '17 at 22:40
  • Possible duplicate of [JScript version availability for WSH installations](https://stackoverflow.com/questions/5497967/jscript-version-availability-for-wsh-installations) – Helen Oct 21 '17 at 16:19

2 Answers2

5

Its a common mistake to make but the Windows Scripting Host supports VBScript and Microsofts own JavaScript implementation called JScript based on the ECMAScript standard. In fact, it can support a number of scripting implementations through its support for Active Scripting languages.

While it shares many similarities with JavaScript, they are not the same (yes, they came from the same place, but that doesn't mean they didn't diverge afterwards). When you use .js files outside of the internet browser (the only browser to support Active Scripting was early versions of Internet Explorer, pre Edge) they are executed using a host program, in this case the Windows Scripting Host. This also applies when using .wsf files.

Edit: I've also updated the tag info as it states can be used, which is incorrect and why so much confusion arises around this topic.


Useful Links

user692942
  • 16,398
  • 7
  • 76
  • 175
  • See above. I am also aware that Windows Scripting Host supports other scripting languages such as VBScript. That doesn't really answer the question I asked which was how to determine which parts of the ECMAScript implementation called JScript (and often referred to as JavaScript) are supported by Windows Scripting Host on a particular computer at a particular time. – JDMorganArkansas Oct 12 '17 at 20:52
  • @JDMorganArkansas in which case why tag it JavaScript? Doing so just leads to more confusion. Fact is, JScript was last updated back in IE 9, so don't expect the latest JavaScript features to work. As for a definitive list of what it does and doesn't support, I doubt such a list exists in the public domain. [Wikipedia has quite a comprehensive list](https://en.wikipedia.org/wiki/JScript) of what version of JScript matches a "similar" version of JavaScript if that helps? – user692942 Oct 12 '17 at 21:38
  • 1
    Thank you for your numerous clarifications. This helps a lot. I will look more closely at the documentation you have provided links to. I notice from Wikipedia that Windows Script Host can host other scripting languages than the default JScript and VBScript, including some that appear to implement more advanced versions of ECMAScript. I can use the workaround for Date.now() for my current needs, but if I need some more advanced features of ECMAScript in WSH, I may look into invoking other scripting engines. – JDMorganArkansas Oct 13 '17 at 15:40
2

i started heavily studying Jscript about 2 years ago. From my experience

  • no classes
  • no imports
  • no Lambas
  • no "let"
  • no "const"
  • no fun

this is the state of what JS looked like when i first began programming back in 2012. At this time all the above features was the gonna be the next big thing in EcmaScript 6.

So my educated guess would be EcmaScript 5.

you can still make classes with the traditional ES5 syntax.

function FunctionButClass(a,b){
    this.Square = function(){ return a*b; }
}
var squared = new FunctionButClass(4,4).Square();

the prototype syntax works as well.

function PrototypeSyntax(a,b){
    this.a = a;
    this.b = b;
}
PrototypeSyntax.prototype.Square = function(){
    return this.a*this.b;
}

also note that the entirety of the DOM is absent, so no document.getElementById("") everything is run through the WScript.CreateObject("")

note2: the DOM IS available in Jscript through .HTA files. But remember

WScript.CrateObject("Scripting.FilesSystemObject");

now becomes:

new ActiveXObject("Scripting.FilesSystemObject")

CyberFox
  • 780
  • 6
  • 24