New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Define the "self" global name #650
Comments
Why not use |
I recommend we go with global which is stage 3 and is in the TC39 process |
@benjamingr which is now not going forward with Because of the global debacle I would tend to agree with @guybedford while we await the outcome of the stuck TC39 proposal. |
@ljharb - any strong opinions here? |
For something node-like, I’d suggest either providing what node does - global - or nothing, pending the new name landing in the language (which will never be “self”). |
Well, if the new name is already selected - what is it? 😅 |
Since it’s still in the process of shipping to browsers, and since there’s a real risk of trolling and of it being not web compatible to do so, I’m trying to keep it under the radar, and I’d ask everyone here to do so as well. Please contact me privately if there’s an urgency to know. |
@ljharb 😮 ok. As far as I'm concerned there's no urgency to know. For what it's worth I think it's entirely reasonable for the TC to not put up with trolling at any amount or capacity. I recommend we wait for the TC. |
I don’t necessarily mean in a specific arena; I’m talking like people putting up websites or publishing packages that intentionally conflict with the name. |
My opinion then is to just wait for the public TC39 announcement. I don't think there is any rush, and TC39 should still be ahead of a stable Deno, would be my guess. |
'self' gets my NeXT vote. |
Why don't we just use all of them? global, self, and window? |
Using |
All works. Let there code break, easy to fix. I think there is better ways to test for browser. Maybe testing for browser on a server is not critical either. |
According to https://github.com/tc39/proposal-global/blob/master/spec.md |
I personally prefer Deno is probably closer to node than to a web browser. See also tc39/proposal-global#36 |
deno could certainly use |
deno seems already having
|
@ry is this still relevant with our current approach? |
We have |
@ry @kitsonk If we don't have |
One can just patch like I make an 'und' that is 'undefined'... no? this = self or what have you. Anyway I would think it is not impossible to cover the bases internally by default and have all things desired or needed without a painful impact on performance or memory, or is that wrong in this case? |
Sorry I closed this too soon. I do want to have “self” in workers. |
Yeah, sorry... The original post was suggesting Another somewhat tangental consideration is that we only have one type library. Ideally we would have 3 type libraries for Deno. One common, and then one small main runtime and one small worker library. We would also need to instruct the compiler if it is main or worker code to maximise the type safety. I would suggest we tackle all this under a different issue though. I originally opened #1866 to deal with that, though it isn't explicit enough. |
I still hate that the web global object is Deno could however decide to just use |
For consistency with the web, any usage of |
I meant only have the ECMAScript properties on it by default. |
might be worth mentioning that:
declare global {
function startsWithPound(text: string): boolean;
}
globalThis.startsWithPound = text => text.startsWith('#')
globalThis.startsWithPound('some text');
// above passes type checks and gets proper inference for function's argument. |
Is the support of "this" an option for Deno ? |
@morille ES Modules must have their |
@ljharb I understand that but it does not affect the main context AFAIK. |
It affects any place where |
We should close this IMO @ry. We have |
[deno](https://deno.land) [doesn't support self](denoland/deno#650) so globalThis should get it to work there but, it's not supported in edge and IE. So, inorder to shim we can use the polyfill from [mozilla docs on globalThis](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/globalThis)
The most widely available global is
self
as it is in both workers and in the main window in browsers.It would be very useful to define this global for cross-platform support.
As a further point it could even be worth having it replace
window
sincetypeof window
is typically done for anisBrowser
detection, while the same cannot necessarily be said ofself
.The text was updated successfully, but these errors were encountered: