以navigator.userAgent为例的JavaScript箭头函数

以navigator.userAgent为例的JavaScript箭头函数,javascript,user-agent,indexof,arrow-functions,navigator,Javascript,User Agent,Indexof,Arrow Functions,Navigator,下面是一个简单的示例,说明如何使用Window对象的navigator.userAgent属性检测浏览器。有人能解释一下这段代码的最新一行实际上做了什么,以及为什么这里需要toLowerCase()方法吗 结束箭头功能 环绕箭头函数的分组运算符的结尾 使用参数调用函数 争论 为什么这里需要toLowerCase()方法 因为它正在进行不区分大小写的比较对它们的工作原理进行一些研究。 const browser = ((agent) => { switch (true) {

下面是一个简单的示例,说明如何使用
Window
对象的
navigator.userAgent
属性检测浏览器。有人能解释一下这段代码的最新一行实际上做了什么,以及为什么这里需要
toLowerCase()
方法吗

结束箭头功能


环绕箭头函数的分组运算符的结尾


使用参数调用函数


争论


为什么这里需要toLowerCase()方法

因为它正在进行不区分大小写的比较

对它们的工作原理进行一些研究。
const browser = ((agent) => {
    switch (true) {
        case agent.indexOf("edge") > -1: return "edge";
        case agent.indexOf("edg") > -1: return "chromium based edge (dev or canary)";
        case agent.indexOf("opr") > -1 && !!window.opr: return "opera";
        case agent.indexOf("chrome") > -1 && !!window.chrome: return "chrome";
        case agent.indexOf("trident") > -1: return "ie";
        case agent.indexOf("firefox") > -1: return "firefox";
        case agent.indexOf("safari") > -1: return "safari";
    default: return "other";
    }
}) (window.navigator.userAgent.toLowerCase());
}
)
(...)
window.navigator.userAgent.toLowerCase()