codeing or artist ?
记得大学第一节编程课,教授说,"如果一件事儿有对错,那么是科学。如果有美丑好坏,那么是艺术。" 一个能顺利运行还能让人阅读时体验思维美妙的代码,就是艺术和科学的结合。能运行的程序并不是好程序,能当作文章来读的才是。在我看来代码是一种特殊的文体,程序猿其实会写诗。
 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

 

posted on 2016-08-31 12:11  codeing-or-artist-??  阅读(297)  评论(0编辑  收藏  举报