插件写法之脚本运行环境,mac和window检测

(function(root, factroy){   /* * 在这里进行对脚本运行环境的检测判断 * 浏览器中 有window对象 * node.js服务器端 有Global对象 */ if(root === undefined){ console.log("请注意,这是Node.js运行环境") }else{ console.log("请注意,这是浏览器运行环境") }

 

// 下在是判断mac和widow的方法 let isSystem= function(){ /** * 是否为mac系统 * */ let isMac = function() { return 'mac系统'+/macintosh|mac os x/i.test(navigator.userAgent); }(); /** * 是否为windows系统 * */ let isWindows = function() { return 'window'+/windows|win32/i.test(navigator.userAgent); }(); console.log("是否MAC系统"+isMac," , "+"是否window系统"+isWindows) return 'isSys'; }(); // isSystem(); console.log(isSystem)   })(this,function(){   下面是自己的工具代码 })

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 [email protected] 举报,一经查实,本站将立刻删除。

相关推荐