I’d like to modify the prototype of whatever object is responsible for .getElementById()
I know document does not have a prototype, so what object is .getElementById() actually attached to?
Edit: so turns out document does have a prototype (thanks Kevin). I feel silly.
It is false that
documentdoes not have a prototype.Regarding the
getElementByIdmethod, I don’t know what specifications have to say, but the location differs between Safari and Firefox, so it should be treated as an implementation detail. Do not rely on the location of the definition. You can always override it directly ondocument.That said, I investigated and on Firefox 8.0, the method is defined on
document‘s prototype:On Safari (and therefore probably also Chrome and other WebKit derivatives), it is on
document‘s prototype’s prototype:You can do research of your own using the browsers’ object inspectors to look up the prototype chain, or using
Object.getPrototypeOfandhasOwnProperty.To override
document.getElementByIdwhile keeping the original around, do something like this:Note that this operates regardless of where the original method is in the prototype chain.