(function (prototype, slice, nativeContains, nativeRemove) {
function contains(token) {
if (typeof token === 'object' && typeof token.test === 'function') {
return slice.call(this).filter(function (item) {
return token.test(item);
});
}
return nativeContains.apply(this, arguments);
}
function remove(token) {
if (typeof token === 'object' && typeof token.test === 'function') {
return slice.call(this).filter(function (item) {
return token.test(item) && !nativeRemove.call(this, item);
}, this);
}
return nativeRemove.apply(this, arguments);
}
nativeContains = prototype.contains;
nativeRemove = prototype.remove;
prototype.contains = contains;
prototype.remove = remove;
})(DOMTokenList.prototype, Array.prototype.slice);
Something like this? If there’s actually any demand for this, consider it CC0, and I’ll throw it on GitHub. My feature-creep brain says this is just one step away from accepting your own methods.