I have to agree with @JMichaelTX here. If you intend on sharing your scripts with others, then you have to write to the lowest common denominator.
If this really works seamlessly, I might consider a workflow where I write using the new Syntax Sugar, then running it through the converter before sharing a script. But to me, that opens the door for a lot of potential errors, including forgetting to do it, and not having been testing the actual code I post.
ES6 does introduce some new syntactic sugar (the destructuring assignments, fat arrow syntax for anonymous functions etc), but it would be misleading to imply that that was the main story - the key changes are more architectural – new forms of name binding, optimisation of tail recursion, new data structures etc.
There are some very significant changes in some parts that go beyond syntactic sugar, unless by “syntactic sugar" you mean anything that can be translated back to ES5. I think a “normal” class structure is probably the most obvious and important change. (I have only looked into this a little — I still don't understand the difference between delegation in previous versions of JS and the new class inheritance mechanism.)
My original question was whether Safari 10 and JXA in implement ES6 in El Capitan, because I think that is a huge development and never realized it before, although the occasional mention of ES6 in this forum was gradually making its way into my awareness. I'm just surprised no-one has just come out and said that you can now use ES6 and that that opens significant new paths in JS development. Certainly not all scripts are intended for distribution to others. And if the back-translation tools really work, writing in ES6 wouldn't be much of a hinderance anyway.
Wait, I just realized what you’ve been saying. Damn Apple and their OS names.
You’ve been saying that El Capitan (10.11) now supports ES6. Holy Crap! In my mind, I kept reading that as Sierra (10.12), not El Cap, i.e. NOT the version I’m on, but the one I don’t want to upgrade to yet.
So I just checked it out, and you’re right, it certainly is supported now.
Well now, this may change my opinion. At least if not now, in the near future 3-6 months down the road.
So thanks for pointing this out! I’ve been misreading this entire thread!
I agree ES6 is the natural medium to work in - tail recursion optimisation lends it well to functional composition for example.
On the versioning issue, the Safari 10 JSC was introduced with Sierra, and I wasn’t aware that subsequent upgrades had introduced it to El Capitan. (An El Capitan machine which I have just reached for is still running the SF9 ES5 JSC, though it may not be fully upgraded to the latest El Capitan).
In any case, I don’t think you can rely on machines running anything before Sierra being able to run ES6 JavaScript in the Automation JSContext. (As embedded in Script Editor, osascript etc)
Safari 10.0, which I am running on El Capitan, does officially, and supposedly completely, support ES6 (see also Features - Safari for Developers), This is truly remarkable (and eliminates the only reason I could think of to ever upgrade past El Capitan). It never occurs to me to look at release notes for Apple applications, as opposed to OS-X in general.
I have been unable so far to determine the situation with JXA, although ES6 Features in JXA · dtinth/JXA-Cookbook Wiki says “From my experimentation, it turned out that JXA supports some ES6 features!”
You would certainly expect Apple to make a big deal about Safari and JXA support for ES6. That it didn't is also truly remarkable.
You would also think I would have been able to find all this by searching the web without first posting it as a question. (A simple Google search — (site:apple.com ECMAscript) brought up the information about Safari as a top hit, now that I knew what to look for.)
Safari 10.0, which I am running on El Capitan, does officially, and supposedly completely, support ES6
Yes, you can certainly run ES6 code in a Safari 10 browser context, regardless of the OS that it's installed on (the browser context doesn't of course, include the Automation library object).
I think you may find, however, that installing Safari 10 on a pre Sierra OS doesn't in itself affect or upgrade the system copy of JSC at:
Even simpler, just stick with ES5 to ensure broadest compatibility with users.
Unless, of course, there is some compelling reason for a specific use case for ES6.
Is ES6 mostly (completely?) a productivity update, or does it provide any capability that could not be done with ES5?
The major ones as I see it (depending on your programming background and preferences) are as follows. These links actually link to the first topic under the heading shown here — there is an outline on the left of the page, but no links to the headings.) I'd say that roughly the topics in first half of the outline shown are primarily syntactic sugar, but the rest contains substantial, and in some cases highly significant, additions. (It looks like at least a few features are influenced by node.js.)
I'm not sure I understand exactly what "SF 9" means
Does it mean JXA compliance in El Capitan 10.11.6?
Is that just the browser Safari Ver 9?
I'm running Safari 10.0.3 (11602.4.8.0.1) on macOS 10.11.6
But don't think the col "SF 10" applies?
Are the column titles defined anywhere? I couldn't find them.
IAC, to make it more readable, and to filter down the list to those functions that do work with "SF 9", I copied the table to Excel.
###Excel Table of ES6 Compatibility for SF 9, SF 10 JXA ES6 Compliance.xlsx.zip (76.3 KB)
I have set the Excel filter to show those rows where the "SF 9" col does NOT start with "0", meaning it has some compliance.