move ES6 feature detection from home1.css to home1.js
Combine the two inline script blocks into a single try/catch using new Function() so old browsers fail gracefully. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
co-authored by
Claude Opus 4.6
parent
9b74aa26a8
commit
5a2bc3b4cb
@@ -608,43 +608,6 @@
|
|||||||
});
|
});
|
||||||
</script>
|
</script>
|
||||||
|
|
||||||
<!-- If browser is pre-ES6, show a warning-->
|
|
||||||
<script>
|
|
||||||
window.isES6 = false;
|
|
||||||
</script>
|
|
||||||
<script>
|
|
||||||
<!-- test ES6 functionality -->
|
|
||||||
// Arrow functions support
|
|
||||||
() => {};
|
|
||||||
|
|
||||||
// Class support
|
|
||||||
class __ES6FeatureDetectionTest {}
|
|
||||||
|
|
||||||
// Object initializer property and method shorthands
|
|
||||||
let es6a = true;
|
|
||||||
let es6b = {
|
|
||||||
es6a,
|
|
||||||
es6c() {
|
|
||||||
return true;
|
|
||||||
},
|
|
||||||
es6d: [1, 2, 3],
|
|
||||||
};
|
|
||||||
|
|
||||||
// Object destructuring
|
|
||||||
let { es6c, es6d } = es6b;
|
|
||||||
|
|
||||||
// Spread operator
|
|
||||||
let es6e = [...es6d, 4];
|
|
||||||
|
|
||||||
// ternary operator
|
|
||||||
let es6f = es6a ? "ternary" : "no ternary";
|
|
||||||
|
|
||||||
// nullish coalescing
|
|
||||||
es6a ??= 10;
|
|
||||||
|
|
||||||
window.isES6 = true;
|
|
||||||
</script>
|
|
||||||
|
|
||||||
<script type="text/javascript">
|
<script type="text/javascript">
|
||||||
window.onload = function () {
|
window.onload = function () {
|
||||||
<!-- display the error message if feature detection flags old browser -->
|
<!-- display the error message if feature detection flags old browser -->
|
||||||
|
|||||||
@@ -1,3 +1,38 @@
|
|||||||
|
// ES6 feature detection
|
||||||
|
(function () {
|
||||||
|
window.isES6 = false;
|
||||||
|
try {
|
||||||
|
new Function([
|
||||||
|
"// Arrow functions",
|
||||||
|
"() => {};",
|
||||||
|
"",
|
||||||
|
"// Class support",
|
||||||
|
"class __ES6FeatureDetectionTest {}",
|
||||||
|
"",
|
||||||
|
"// Object initializer property and method shorthands",
|
||||||
|
"let es6a = true;",
|
||||||
|
"let es6b = {",
|
||||||
|
" es6a,",
|
||||||
|
" es6c() { return true; },",
|
||||||
|
" es6d: [1, 2, 3],",
|
||||||
|
"};",
|
||||||
|
"",
|
||||||
|
"// Object destructuring",
|
||||||
|
"let { es6c, es6d } = es6b;",
|
||||||
|
"",
|
||||||
|
"// Spread operator",
|
||||||
|
"let es6e = [...es6d, 4];",
|
||||||
|
"",
|
||||||
|
"// Ternary operator",
|
||||||
|
"let es6f = es6a ? 'ternary' : 'no ternary';",
|
||||||
|
"",
|
||||||
|
"// Nullish coalescing",
|
||||||
|
"es6a ??= 10;",
|
||||||
|
].join("\n"))();
|
||||||
|
window.isES6 = true;
|
||||||
|
} catch (e) {}
|
||||||
|
})();
|
||||||
|
|
||||||
const hamburgerComponent = {
|
const hamburgerComponent = {
|
||||||
template: `<div class="bigger-fancy-text">
|
template: `<div class="bigger-fancy-text">
|
||||||
<i v-bind:class="item.icon" aria-hidden="true"></i>
|
<i v-bind:class="item.icon" aria-hidden="true"></i>
|
||||||
|
|||||||
Reference in New Issue
Block a user