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

Recommended approach for globally setting undefined #1

Open
jackjocross opened this issue Mar 5, 2018 · 8 comments
Open

Recommended approach for globally setting undefined #1

jackjocross opened this issue Mar 5, 2018 · 8 comments
Labels
enhancement New feature or request

Comments

@jackjocross
Copy link

First off, thank you for this helpful package!

Using Babel, undefined is scoped to the module that I import it in, but I want undefined to be a function for my entire site. My current approach is:

import { undefined as undef } from 'undefined-is-a-function';

undefined = undef;

If this is a common use case would you consider adding a utility method?

@donavon
Copy link
Owner

donavon commented Mar 5, 2018

Hmmm... Seems like a lot of manual work. What if it were abstracted away using a helper function? Something like this (just spitballing here):

import { undefined, setGlobal } from 'undefined-is-a-function';
setGlobal('undefined', undefined);

PRs welcome. 😉

@maniator
Copy link
Contributor

maniator commented Mar 5, 2018

@crosscompile you would have to do :

global.undefined = undef;

// or:
window.undefined = undef;

@aarongodin
Copy link

Following the single-responsibility principle, we should probably create a new package on npm called undefined-is-always-a-function. This package already has enough code in it. We wouldn't want our complexity to go up too much.

@donavon donavon added the enhancement New feature or request label Mar 5, 2018
@jackjocross
Copy link
Author

After further investigation, I think we might have a slight issue. According to MDN, modern browsers implement undefined as a non-configurable, non-writable property.

Not sure if this is intended to be a helpful "feature", but we might need to explore other methods to globally set undefined.

@maniator
Copy link
Contributor

maniator commented Mar 5, 2018

screen shot 2018-03-05 at 10 45 05 am

😞

@maniator
Copy link
Contributor

maniator commented Mar 5, 2018

Although, this does work:

screen shot 2018-03-05 at 10 46 31 am

So you would have to do it in a module pattern. or like define it using webpack defines or something?

@jackjocross
Copy link
Author

@maniator I was thinking the same, maybe a webpack plugin or babel transform that defines undefined as a function in each module.

@jackjocross
Copy link
Author

I present, in all it's glory, babel-plugin-undefined-is-always-a-function.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

4 participants