Dev*_*ian 10 javascript jquery userscripts function-prototypes
我正在开发一个UserScript,我认为为Object创建2个Prototype函数会节省更多时间.
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;
};
Run Code Online (Sandbox Code Playgroud)
这两个函数在我的调试控制台上完全正常工作,因为我输入它们,我使用它们,但是当我运行我的脚本时,它会让我的控制台出现一些奇怪的错误.
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
Run Code Online (Sandbox Code Playgroud)
更像是这样,使得Site的JavaScript无法运行.
没有这些功能我的脚本就像魅力一样.我在String上也有更多Prototype,但这很好用
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;
}
Run Code Online (Sandbox Code Playgroud)
在我的用户名录中,我包括
我真的没有得到什么问题,因为在调试控制台上它没有错误或其他什么.
Dip*_*ole 12
我认为这只是jQuery与本机原型的冲突.
所以只有解决方法,我可以找到它来定义属性使用,
Object.defineProperty(Object.prototype, 'Count ',{
value : function() {},
enumerable : false
});
Object.defineProperty(Object.prototype, 'GetEntry ',{
value : function() {},
enumerable : false
});
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
2822 次 |
| 最近记录: |