Remove references to globals through `this` in AMD factories

Fixes #17829

(cherry picked from commit fa4028b647e38d4f1cc183e6db65022f80cb5423)