Join GitHub today
GitHub is home to over 40 million developers working together to host and review code, manage projects, and build software together.
Sign upAssigning to multiple variables in one line throws error #359
Comments
This comment has been minimized.
This comment has been minimized.
|
That is totally valid JS!
If defining /* global jQuery */
var $ = jQuery = require('jquery')If it should not be global, just declare it: var jQuery
var $ = jQuery = require('jquery')even this is valid in var $, jQuery
$ = jQuery = require('jquery')Its also possible to add a "standard" attribute to "standard": {
"globals":["jQuery"]
}This would make your original code work without issue in all your files. I'm going to close this issue for now, but feel free to comment if you have questions/concerns! |
Flet
closed this
Dec 10, 2015
This comment has been minimized.
This comment has been minimized.
|
If I may add, var $ = jQuery = require('jquery')is the same as: var $ = (jQuery = require('jquery'))which unrolls to: jQuery = require('jquery')
var $ = jQuery...which is what standard complains about: declaring jQuery as a global. However, this is fine: var jQuery = require('jquery')
var $ = jQuery
/* ✓ ok */or this: var $, jQuery
$ = jQuery = require('jquery')
/* ✓ also ok */ |
This comment has been minimized.
This comment has been minimized.
|
Thanks so much guys - I always assumed it was declaring the second var, but I totally see how it wouldn't. I appreciate the detailed explanation and options! |
timwis commentedDec 8, 2015
I use this to accommodate bootstrap.js in browserify. It throws the error
"jQuery" is not defined.Have I misunderstood what this does in JavaScript this whole time? I'm under the impression that it sets both
$andjQueryto the value ofrequire('jquery').