drduan / minggeJS

857 stars 143 forks source link

uaMatch 这个函数应该是借鉴或者说抄袭于 jQuery #87

Open xqin opened 8 years ago

xqin commented 8 years ago

MingGeJS 中的代码如下:

    uaMatch = function(ua) {
        ua = ua.toLowerCase();
        var match = /(webkit)[ \/]([\w.]+)/.exec(ua) || /(opera)(?:.*version)?[ \/]([\w.]+)/.exec(ua) || /(msie) ([\w.]+)/.exec(ua) || !/compatible/.test(ua) && /(mozilla)(?:.*? rv:([\w.]+))?/.exec(ua) || [];
        return {
            browser: match[1] || "",
            version: match[2] || "0"
        };
    },

根据搜索引擎, 搜索 uaMatch 关键字, 得到的结果: 以这个为例: http://www.jb51.net/article/26254.htm

文章发表到2011年. image

代码如下:

// Useragent RegExp 
rwebkit = /(webkit)[ \/]([\w.]+)/, 
ropera = /(opera)(?:.*version)?[ \/]([\w.]+)/, 
rmsie = /(msie) ([\w.]+)/, 
rmozilla = /(mozilla)(?:.*? rv:([\w.]+))?/, 
// Keep a UserAgent string for use with jQuery.browser 
userAgent = navigator.userAgent, 

// For matching the engine and version of the browser 
browserMatch, 

// Use of jQuery.browser is frowned upon. 
// More details: http://docs.jquery.com/Utilities/jQuery.browser 
uaMatch: function( ua ) { 
ua = ua.toLowerCase(); 

var match = rwebkit.exec( ua ) || 
ropera.exec( ua ) || 
rmsie.exec( ua ) || 
ua.indexOf("compatible") < 0 && rmozilla.exec( ua ) || 
[]; 

return { browser: match[1] || "", version: match[2] || "0" }; 
} 
browserMatch = jQuery.uaMatch( userAgent ); 
if ( browserMatch.browser ) { 
jQuery.browser[ browserMatch.browser ] = true; 
jQuery.browser.version = browserMatch.version; 
} 

@drduan 正因为我反感JQUERY。 既然这么反感 jQuery, 那抄人家代码做啥?

lincanbin commented 8 years ago

抄袭,明哥的事能叫抄吗?

dsphper commented 8 years ago

孩子不要乱说话,明哥从不抄袭,因为明哥对抄袭的真谛了如指掌。

q545244819 commented 8 years ago

为什么我反感,因为我完全有开发JQUERY的能力,JQUERY的底层我都了如指掌。

你看人家明哥都说了对底层了如指掌了。知道jQuery底层的人,抄jQuery代码不能叫做抄,叫做借鉴。

jamesliu96 commented 8 years ago

人家对JQuery的底层都了如指掌,用了JQuery的区区一个函数,那只能说明哥人家看得起写这个函数的人,被明哥看得起那可是至高无上的荣耀,怎么能说“抄”?你们啊,naive!