domenic / get-originals

A web platform API that allows access to the "original" versions of the global built-in objects' properties and methods
28 stars 1 forks source link

callOriginalMethod: could it take a single string? #1

Closed ljharb closed 6 years ago

ljharb commented 6 years ago

For example, callOriginalMethod('Array.prototype.slice', receiver, ...args) instead of needing to store Array.prototype in the first place?

domenic commented 6 years ago

This was discussed in https://github.com/drufball/layered-apis/issues/6#issuecomment-386650536; definitely on a TODO to explain more. The basic idea is that we don't want to prevent future refactorings on the platform that would move things between prototypes.

ljharb commented 6 years ago

Wouldn't that still be the case tho, if someone did callOriginalMethod(originalArrayPrototype, 'slice', receiver), and the method name was moved?

domenic commented 6 years ago

No, there is no thisArg in the method signature. You need to operate on instances directly.

ljharb commented 6 years ago

ok, so it'd be like "call the original slice method on an array" - and when you say "move things between prototypes", you mean "within levels of the prototype chain" but not "off of the chain entirely"?

domenic commented 6 years ago

Right. A specific concern is that browsers are moving various things between HTMLDocument.prototype and Document.prototype, and the set of which goes where is not interoperable currently. We hope developers don't have to care about this---just supply (the original value of the global) document, and a method/property name, and you'll get the right answer, no matter where the particular browser you're dealing with has put that method/property.

ljharb commented 6 years ago

Makes sense.

Altho, the internal mapping could be 'Old.prototype.method'getOriginal('New.prototype.method') - but the rationale makes sense, so I'll close.