Skip to content
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

global becomes undefined #13027

Closed
macsmac opened this issue May 14, 2017 · 3 comments
Closed

global becomes undefined #13027

macsmac opened this issue May 14, 2017 · 3 comments
Labels
question Issues that look for answers.

Comments

@macsmac
Copy link

macsmac commented May 14, 2017

When I run this code:

Object.keys(global).forEach(k => Object.defineProperty(global, k, {set:console.log}));

global object becomes undefined

typeof global // "undefined"

But

typeof this // "object"

And if I will run Object.keys or Object.defineProperty global does not become undefined. Bug?

@TimothyGu
Copy link
Member

No it is not a bug. global mirrors global.global, and when you define global.global to a setter-only property, global cannot be read anymore, and typeof naturally returns 'undefined'.

@macsmac
Copy link
Author

macsmac commented May 14, 2017

Forget to say: defineProperty throws error "defineProperty called on non-object". We will log key.

Object.keys(global).forEach((k) =>{ console.log(k); Object.defineProperty(global, k, {set:console.log}); });

It logs

global
process
<error>

@mscdex mscdex added the question Issues that look for answers. label May 14, 2017
@macsmac
Copy link
Author

macsmac commented May 14, 2017

Actually got it, because first key is global we defineProperty on it without getter and it becomes undefined and next key cannot be defined

@macsmac macsmac closed this as completed May 14, 2017
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
question Issues that look for answers.
Projects
None yet
Development

No branches or pull requests

3 participants