Remove references to globals through `this` in AMD factories

Fixes #17829

(cherry picked from commit fa4028b647e38d4f1cc183e6db65022f80cb5423)
(cherry picked from commit dcebb97df09699d3e3517dac7189239e0b13880e)