1 var myLibs = { 2 // Use of jQuery.browser is frowned upon. 3 // More details: http://api.jquery.com/jQuery.browser 4 // jQuery.uaMatch maintained for back-compat 5 browser:(function(){ 6 var uaMatch = function(ua){ 7 ua = ua.toLowerCase(); 8 9 var match = /(chrome)[ \/]([\w.]+)/.exec( ua ) || 10 /(webkit)[ \/]([\w.]+)/.exec( ua ) || 11 /(opera)(?:.*version|)[ \/]([\w.]+)/.exec( ua ) || 12 /(msie) ([\w.]+)/.exec( ua ) || 13 ua.indexOf("compatible") < 0 && /(mozilla)(?:.*? rv:([\w.]+)|)/.exec( ua ) || 14 []; 15 16 return { 17 browser: match[ 1 ] || "", 18 version: match[ 2 ] || "0" 19 }; 20 }; 21 22 var matched = uaMatch(navigator.userAgent), 23 browser = {}; 24 25 if (matched.browser){ 26 browser[matched.browser] = true; 27 browser.version = matched.version; 28 } 29 30 // Chrome is Webkit, but Webkit is also Safari. 31 if (browser.chrome){ 32 browser.webkit = true; 33 }else if (browser.webkit){ 34 browser.safari = true; 35 } 36 return browser; 37 })() 38 }; 39 40 console.log(myLibs.browser.mozilla);//true 41 console.log(myLibs.browser.version);//39.0