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

Sourcing multiple files? #582

Closed
maasha opened this issue Aug 3, 2016 · 6 comments

Comments

@maasha
Copy link

commented Aug 3, 2016

If I have a function defined in one file that is used in another file I get warnings on defined but not used and not defined. What can be done?

@dcousens dcousens added the question label Aug 3, 2016

@feross

This comment has been minimized.

Copy link
Member

commented Aug 3, 2016

If you're using a module loading system, like browserify's require() then this won't be an issue.

a.js

exports.foo = function () {}

b.js

var a = require('./a')
a.foo()

But it sounds like you're just including both a.js and b.js in a page via <script> tags.

a.js

function foo () {}

b.js

foo()

index.html

<script src="a.js"></script>
<script src="b.js"></script>

To make the relationship between these files, clear to the linter (and to readers of your code), you should explicitly reference where the foo() function is coming from in b.js.

b.js

window.foo()

That should fix your issue!

@feross feross closed this Aug 3, 2016

@maasha

This comment has been minimized.

Copy link
Author

commented Aug 3, 2016

Great, thanks!

@maasha

This comment has been minimized.

Copy link
Author

commented Sep 15, 2016

One note. The window.foo() explicit call does silence the warning in b.js but in a.js I still get a foo is defined but never used warning

@imjoehaines

This comment has been minimized.

Copy link

commented Sep 15, 2016

In a.js, if you assign your function to window.foo instead of just foo then the warning should go away

@feross

This comment has been minimized.

Copy link
Member

commented Sep 15, 2016

Yep, what @imjoehaines said.

@LinusU

This comment has been minimized.

Copy link
Member

commented Sep 15, 2016

Also see #619 which might influence your decision to use, or not to use, window

@lock lock bot locked as resolved and limited conversation to collaborators May 10, 2018

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
5 participants
You can’t perform that action at this time.