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

(function(root, factroy){
   
/*
* 在这里进行对脚本运行环境的检测判断
* 浏览器中 有window对象
* node.js服务器端 有Global对象
*
* IE11的window.navigator.userAgent.toLowerCase()
* "mozilla/5.0 (windows nt 10.0; wow64; trident/7.0; .net4.0c; .net4.0e;
* .net clr 2.0.50727; .net clr 3.0.30729; .net clr 3.5.30729; infopath.3;
* rv:11.0) like gecko"
*
* 谷歌浏览器window.navigator.userAgent.toLowerCase()
* "mozilla/5.0 (windows nt 10.0; win64; x64) applewebkit/537.36 (khtml, like gecko)
* chrome/71.0.3578.98 safari/537.36"
*/
if(root === undefined){
console.log("请注意,这是Node.js运行环境")
}else{
console.log("请注意,这是浏览器运行环境")
}

// 下在是判断mac和widow的方法
let isSystem= function(){
/** * 是否为mac系统 * */
let isMac = function() {
return /macintosh|mac os x/i.test(navigator.userAgent);
}();
/** * 是否为windows系统 * */
let isWindows = function() {
return /windows|win32/i.test(navigator.userAgent);
}();
console.log("是否MAC系统"+isMac," , "+"是否window系统"+isWindows)
return '判断设备mac或window系统>>>'+'isMac: '+isMac+' ,isWindows: '+isWindows;
}();
console.log(isSystem)
 
 
root.Vue = factory();
 
})(  this === window ? window:global  ,function(){
  下面是自己的工具代码
})
原文地址:https://www.cnblogs.com/andy-lehhaxm/p/10360163.html