Skip to content

Instantly share code, notes, and snippets.

@fearphage
Created September 17, 2009 18:54
Show Gist options
  • Save fearphage/188653 to your computer and use it in GitHub Desktop.
Save fearphage/188653 to your computer and use it in GitHub Desktop.
//! ==UserScript==
//! @include http://*
//! ==/UserScript==
(function(slice, toString, filter) {
// opera bug - DSK-259939
var buggy = filter.call('fPaAiSlS', function(c) { return 'fail'.indexOf(c) == -1; }).join('') != 'PASS';
function addGenerics(klass, methods) {
var fn;
methods.forEach(function(name) {
if ((fn = klass.prototype[name]) && !klass[name]) {
klass[name] = (function() {
return function(obj) {
//opera.postError([fn,obj,toString.call(this),toString.call(obj),slice.call(arguments, 1)].join('\n'));
return fn.apply(
(buggy && (klass == Array) && (toString.call(obj) == '[object String]')
? obj.split('')
: obj
)
,slice.call(arguments, 1)
);
};
})();
}
});
}
addGenerics(Array, 'every filter forEach map reduce reduceRight slice some'.split(' '));
addGenerics(String, 'replace substr'.split(' '));
if (!('name' in Function.prototype)) {
Function.prototype.__defineGetter__('name', function() {
return this.toString().match(/function\s+([^\s\(]+)/) ? RegExp.$1 : 'anonymous';
});
Function.prototype.__defineSetter__('name', function(readonly) { });
}
})(Array.prototype.slice, Object.prototype.toString, Array.prototype.filter);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment