Move properties inside UAItem class into shared prototype

This commit is contained in:
Faisal Salman
2025-11-13 11:42:53 +07:00
parent 5a5b321347
commit 1d8eab09f1

View File

@@ -1191,23 +1191,32 @@
} }
function UAItem (itemType, ua, rgxMap, uaCH) { function UAItem (itemType, ua, rgxMap, uaCH) {
setProps.call(this, [
['itemType', itemType],
['ua', ua],
['uaCH', uaCH],
['rgxMap', rgxMap],
['data', createIData(this, itemType)]
]);
return this;
}
this.get = function (prop) { UAItem.prototype.get = function (prop) {
if (!prop) return this.data; if (!prop) return this.data;
return this.data.hasOwnProperty(prop) ? this.data[prop] : undefined; return this.data.hasOwnProperty(prop) ? this.data[prop] : undefined;
}; };
this.set = function (prop, val) { UAItem.prototype.set = function (prop, val) {
this.data[prop] = val; this.data[prop] = val;
return this; return this;
}; };
this.setCH = function (ch) { UAItem.prototype.setCH = function (ch) {
this.uaCH = ch; this.uaCH = ch;
return this; return this;
}; };
this.detectFeature = function () { UAItem.prototype.detectFeature = function () {
if (NAVIGATOR && NAVIGATOR.userAgent == this.ua) { if (NAVIGATOR && NAVIGATOR.userAgent == this.ua) {
switch (this.itemType) { switch (this.itemType) {
case BROWSER: case BROWSER:
@@ -1251,7 +1260,7 @@
return this; return this;
}; };
this.parseUA = function () { UAItem.prototype.parseUA = function () {
if (this.itemType != RESULT) { if (this.itemType != RESULT) {
rgxMapper.call(this.data, this.ua, this.rgxMap); rgxMapper.call(this.data, this.ua, this.rgxMap);
} }
@@ -1272,7 +1281,7 @@
return this; return this;
}; };
this.parseCH = function () { UAItem.prototype.parseCH = function () {
var uaCH = this.uaCH, var uaCH = this.uaCH,
rgxMap = this.rgxMap; rgxMap = this.rgxMap;
@@ -1374,17 +1383,6 @@
return this; return this;
}; };
setProps.call(this, [
['itemType', itemType],
['ua', ua],
['uaCH', uaCH],
['rgxMap', rgxMap],
['data', createIData(this, itemType)]
]);
return this;
}
function UAParser (ua, extensions, headers) { function UAParser (ua, extensions, headers) {
if (typeof ua === TYPEOF.OBJECT) { if (typeof ua === TYPEOF.OBJECT) {