Rewrite util.extend to a clone version

This commit is contained in:
Malash
2015-10-10 14:50:15 +08:00
parent 20ea67ed1d
commit 792dc0246a
3 changed files with 12 additions and 10 deletions

View File

@@ -45,12 +45,15 @@
var util = {
extend : function (regexes, extensions) {
for (var i in extensions) {
if ("browser cpu device engine os".indexOf(i) !== -1 && extensions[i].length % 2 === 0) {
regexes[i] = extensions[i].concat(regexes[i]);
var margedRegexes = {};
for (var i in regexes) {
if (extensions[i] && extensions[i].length % 2 === 0) {
margedRegexes[i] = extensions[i].concat(regexes[i]);
} else {
margedRegexes[i] = regexes[i];
}
}
return regexes;
return margedRegexes;
},
has : function (str1, str2) {
if (typeof str1 === "string") {
@@ -531,7 +534,7 @@
/(alcatel|geeksphone|huawei|lenovo|nexian|panasonic|(?=;\s)sony)[_\s-]?([\w-]+)*/i
// Alcatel/GeeksPhone/Huawei/Lenovo/Nexian/Panasonic/Sony
], [VENDOR, [MODEL, /_/g, ' '], [TYPE, MOBILE]], [
/(nexus\s9)/i // HTC Nexus 9
], [MODEL, [VENDOR, 'HTC'], [TYPE, TABLET]], [
@@ -651,7 +654,7 @@
], [VENDOR, MODEL, [TYPE, MOBILE]], [
/(i-STYLE2.1)/i // i-mobile i-STYLE 2.1
], [[MODEL, 'i-STYLE 2.1'], [VENDOR, 'i-mobile'], [TYPE, MOBILE]], [
/(mobiistar touch LAI 512)/i // mobiistar touch LAI 512
], [[MODEL, 'Touch LAI 512'], [VENDOR, 'mobiistar'], [TYPE, MOBILE]], [
@@ -794,7 +797,6 @@
ua = uastring;
return this;
};
this.setUA(ua);
return this;
};
@@ -853,7 +855,7 @@
}
// jQuery/Zepto specific (optional)
// Note:
// Note:
// In AMD env the global scope should be kept clean, but jQuery is an exception.
// jQuery always exports to global scope, unless jQuery.noConflict(true) is used,
// and we should catch that.