Skip to content

Instantly share code, notes, and snippets.

@elusiveunit
Forked from DaBs/es6-feature-detection.js
Last active October 20, 2018 11:24
Show Gist options
  • Save elusiveunit/a4762101eea0f32407649ac94cad04d2 to your computer and use it in GitHub Desktop.
Save elusiveunit/a4762101eea0f32407649ac94cad04d2 to your computer and use it in GitHub Desktop.
var str = 'class ಠ_ಠ extends Array {constructor(j = "a", ...c) {const q = (({u: e}) => {return { [`s${c}`]: Symbol(j) };})({});super(j, q, ...c);}}' +
'new Promise((f) => {const a = function* (){return "\u{20BB7}".match(/./u)[0].length === 2 || true;};for (let vre of a()) {' +
'const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()];break;}f(new Proxy({}, {get: (han, h) => h in han ? han[h] ' +
': "42".repeat(0o10)}));}).then(bi => new ಠ_ಠ(bi.rd));';
try {
eval(str);
} catch(e) {
alert('Your browser does not support ES6!')
}
/*
* All credits to Netflix for providing this approach to ES6 feature detection. Although this could be written in many different ways
* this proved to be the most direct and elegant approach for me.
* License: MIT
*/
class ಠ_ಠ extends Array {
constructor(j = "a", ...c) {
const q = (({u: e}) => {
return { [`s${c}`]: Symbol(j) }
})({})
super(j, q, ...c)
}
}
new Promise((f) => {
const a = function* () {
return "\u{20BB7}".match(/./u)[0].length === 2 || true
}
for (let vre of a()) {
const [uw, as, he, re] = [new Set(), new WeakSet(), new Map(), new WeakMap()]
break
}
f(new Proxy({}, {
get: (han, h) => h in han ? han[h] : "42".repeat(0o10)
}))
}).then(bi => new ಠ_ಠ(bi.rd))
@elusiveunit
Copy link
Author

Basic detection of the following features:

  • Classes
  • Enhanced object literals
  • Template strings
  • Destructuring
  • Default + Rest + Spread
  • let + const
  • Iterators + for..of
  • Generators (function* ())
  • Unicode (ಠ_ಠ)
  • Proxies
  • Symbols
  • Subclassable built-ins
  • Promises
  • Arrows
  • New additions to APIs:
    • Math
    • Number
    • String
    • Array
    • Object

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment