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