问题
I have a line in my source code written by someone else:
var campaignLimits = 10, campaignsArray = new Array();
I just wanted to know, whether campaignsArray
here becomes global variable, or the var
applies to campaignsArray
as well?
回答1:
Assuming you have not used any programming pattern, If its written inside a function then its not global.
(function() { var campaignLimits = 10, campaignsArray = new Array(); })();
as @phoa commented it is same as
(function() { var campaignLimits = 10; var campaignsArray = new Array(); })();
Try it in your console and see whether you will be able to access campaignsArray.
来源:https://stackoverflow.com/questions/40883472/defining-multiple-variables-with-one-var-keyword-in-javascript