1

What is the best way to include two variables for a single package that is required in JavaScript?

I have an example here:

$ = require('jquery');

At the moment I simply use $ however some of my project uses jQuery which I cannot change.

$, jQuery = require('jquery');

However this did not work which was expected to be honest.

This works however it isn't ideal as it will be requiring the package twice wont it?

$ = require('jquery');
jQuery = require('jquery');

Thanks

3
  • Why not just $ = require('jquery'); jQuery = $; Commented Aug 8, 2017 at 11:55
  • Can you explain the context of this? If jQuery is a global variable then why require it? Commented Aug 8, 2017 at 11:55
  • Why not using IIFE? (function ($) { /* jquery code here */ }(jQuery)) Commented Aug 8, 2017 at 11:59

1 Answer 1

3
var $ = jQuery = require('jquery');
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.