sockjs / sockjs-client

WebSocket emulation - Javascript client
MIT License
8.45k stars 1.3k forks source link

replace global with globalThis #633

Closed lil5 closed 8 months ago

lil5 commented 1 year ago

Fixes #581

Problem

On the web you can use window, self, or frames - but in Web Workers only self will work. In Node.js none of these work, and you must instead use global. The this keyword could be used inside functions running in non–strict mode, but this will be undefined in modules and inside functions running in strict mode.

Fix

The globalThis property provides a standard way of accessing the global this value (and hence the global object itself) across environments.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis

JulesLecuir commented 11 months ago

Thanks @lil5 ! Looking forward to having this PR merged :)

lil5 commented 11 months ago

@auvipy I'm not sure how to do that more than I've already done.

Have you looked at the list of files I changed?

Tests that previously used global now use globalThis and it works just fine.

lil5 commented 11 months ago

@auvipy Would you like me to run npm run glup release and commit the /dist/ files before you merge?