Skip to content
This repository has been archived by the owner on Jul 30, 2018. It is now read-only.

Modules being emitted in strict mode breaks global.ts #100

Closed
kitsonk opened this issue Jan 5, 2016 · 7 comments
Closed

Modules being emitted in strict mode breaks global.ts #100

kitsonk opened this issue Jan 5, 2016 · 7 comments
Labels
Milestone

Comments

@kitsonk
Copy link
Member

kitsonk commented Jan 5, 2016

As of TypeScript 1.8, all modules are emitted with the "use strict"; prologue (see: microsoft/TypeScript#5765). This causes global.ts to return undefined at runtime, versus the global scope.

@kitsonk
Copy link
Member Author

kitsonk commented Jan 5, 2016

@jason0x43 mentioned the following should work in strict mode:

const global = (1,eval)('this');

@kitsonk kitsonk closed this as completed in 950bfab Jan 5, 2016
@kitsonk
Copy link
Member Author

kitsonk commented Jan 6, 2016

Actually, I settled on const global = Function('return this')(); as it seems more clear what the intent is.

@kfranqueiro
Copy link
Member

I was thinking something along those lines too; is there a reason to prefer that over (function () { return this; }());?

@jason0x43
Copy link
Member

this is undefined for regular function calls in strict mode.

@kfranqueiro
Copy link
Member

Oh, derp, that is what we were doing (I had thought we were doing something more specific). Nevermind. Though I wouldn't have expected new Function to behave differently then.

@kitsonk
Copy link
Member Author

kitsonk commented Jan 6, 2016

Yeah, I didn't either, but @DanielRosenwasser pointed me to a StackOverflow and it passes the tests.

@jason0x43
Copy link
Member

Functions created with the Function constructor don't inherit strictness, so this points to the global object as it would in non-strict mode.

@dylans dylans added this to the Milestone 2 milestone Jan 10, 2018
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

No branches or pull requests

4 participants