比如下面的代码:(function(){"usestrict";!function(i){varn,e,r,o,t,a;returnr=null,n=/WebKit\/([\d.]+)/,e={Android:/(Android)\s+([\d.]+)/,ipad:/(iPad).*OS\s([\d_]+)/,iphone:/(iPhone\sOS)\s([\d_]+)/,Blackberry:/(BlackBerry|BB10|Playbook).*Version\/([\d.]+)/,FirefoxOS:/(Mozilla).*Mobile[^\/]*\/([\d\.]*)/,webOS:/(webOS|hpwOS)[\s\/]([\d.]+)/},i.isMobile=function(){returnthis.environment(),r.isMobile},i.environment=function(){vari,n;returnr||(n=navigator.userAgent,i=t(n),r={browser:o(n),isMobile:!!i,screen:a(),os:i}),r},o=function(i){vare;returne=i.match(n),e?e[0]:i},t=function(i){varn,r,o;for(rine)if(o=i.match(e[r])){n={name:"iphone"===r||"ipad"===r||"ipod"===r?"ios":r,version:o[2].replace("_",".")};break}returnn},a=function(){return{width:window.innerWidth,height:window.innerHeight}}}(Quo)}).call(this);这样写有什么好处?什么时候应该这样做?还有其他方式么?
相关分类