I'm developing a UserScript and i thought it would be more time saving to create 2 Prototype functions for Object.
Object.prototype.Count = function() {
var size = 0, key;
for (key in this) {
if (this.hasOwnProperty(key)) {
size++;
}
}
return size;
};
Object.prototype.GetEntry = function(index) {
var size = 0, key;
for (key in this) {
if (this.hasOwnProperty(key)) {
if (size == index)
return this[key];
size++;
}
}
return null;
};
This 2 Functions are Working perfectly fine on my Debug Console as i Type them, and i use them, however when i'm running my Script, it get some weird errors flooding my console.
Uncaught TypeError: U[a].exec is not a function
Uncaught TypeError: (ec[b] || []).concat is not a function
Uncaught TypeError: X[g].exec is not a function
Uncaught TypeError: (Qn[t] || []).concat is not a function
And more like that, making Site's JavaScript not working.
Without These Functions my Script works like charm. I also have on more Prototype on String, but this is working just fine
String.prototype.between = function(prefix, suffix) {
s = this;
var i = s.indexOf(prefix);
if (i >= 0) {
s = s.substring(i + prefix.length);
}
else {
return '';
}
if (suffix) {
i = s.indexOf(suffix);
if (i >= 0) {
s = s.substring(0, i);
}
else {
return '';
}
}
return s;
}
In my userscript i'm including
I really don't get what's the problem since on debug console it is working without errors or something.
I assume that this is nothing but jQuery conflict with native prototype.
So only workaround I can find it to define properties using,
Object.defineProperty(Object.prototype, 'Count ',{
value : function() {},
enumerable : false
});
Object.defineProperty(Object.prototype, 'GetEntry ',{
value : function() {},
enumerable : false
});
jQuery conflict with native prototype.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With