Mathias Bynens 4/18/2019

A horrifying `globalThis` polyfill in universal JavaScript

Read Original

This technical article details the challenges of writing a correct `globalThis` polyfill for universal JavaScript. It explains why simple alternatives like `window` or `self` fail in certain contexts (Node.js, workers, modules) and explores creative, albeit horrifying, solutions using the Function constructor or indirect eval to access the global `this` value.

A horrifying `globalThis` polyfill in universal JavaScript

Comments

No comments yet

Be the first to share your thoughts!

Browser Extension

Get instant access to AllDevBlogs from your browser

Top of the Week

No top articles yet