-
-
Save bendc/d7f3dbc83d0f65ca0433caf90378cd95 to your computer and use it in GitHub Desktop.
var supportsES6 = function() { | |
try { | |
new Function("(a = 0) => a"); | |
return true; | |
} | |
catch (err) { | |
return false; | |
} | |
}(); |
@triblondon Yup, the critical test is the a = 0
(all browsers supporting default parameters have a fairly complete support of ES6 -- for example, Edge 13 will be rejected by this test despite a decent ES6 coverage).
<html>
<head>
<script>
if (typeof Symbol === 'undefined') {
document.write('<script crossorigin="anonymous" src="https://polyfill.io/v3/polyfill.min.js?features=es6,es7&flags=gated"><\/script>')
}
</script>
</head>
<body>
</body>
</html>
@triblondon Yup, the critical test is the
a = 0
(all browsers supporting default parameters have a fairly complete support of ES6 -- for example, Edge 13 will be rejected by this test despite a decent ES6 coverage).
I wanna know how to prove “all browsers supporting default parameters have a fairly complete support of ES6”
Thankfully, if you can show links or refs
MediaWiki previously used this snippet and is now updating it to also test for these ES2017 features:
- Trailing commas in function parameters
- Async functions
See the update in patchset 1141401.
Ensuring ES2015 (ES6) grammar and syntax support:
new Function( '(a = 0) => a' );
Ensuring ES2017 (ES8) grammar and syntax support:
new Function( 'async (a = 0,) => a' );
The crucial test is the one for trailing commas, as it was the last ES2017 feature to be implemented (for instance, in Chrome 58).
You can find more details in the "Feature summary" table at the end of this Feature support list on caniuse.com.
@rik optimising for the modern browsers, you could
<link rel=preload>
it