插件写法之脚本运行环境,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(){
  下面是自己的工具代码
})

猜你喜欢

转载自www.cnblogs.com/andy-lehhaxm/p/10360163.html