Aşağıdaki kod try-catch bloğu ile kullanıcının tarayıcısının ES6 desteğini bize verebilir.
var supportsES6 = function() {
try {
new Function("(a = 0) => a")
return true
}
catch (err) {
return false
}
}()
Bu kod, kullanıcı tarayıcısının ES6 desteğini tamamıyle ve her özelliğiyle doğrulamasa da genel hatlarıyla bize bilgi verebilir.
if (!supportsES6) {
alert('Tarayıcınız ES6'yı desteklemiyor')
window.location.href('/browser-not-supperted')
}
Şu yöntemi kullanarak ES6 kodları içeren JavaScript dosyamızı sayfanın gövdesine dahil edebiliriz.
if (supportsES6) {
var script = document.createElement("script")
script.src = "es6-iceren-js-dosyasi.js"
document.head.appendChild(script)
}