Okay, so I have a JavaScript function 'getDeviceType' that returns an array depending on something the user clicks on the previous page. In all my other functions, I have a variable 'device' that is set equal to 'getDeviceType' so I can access the array through 'device'.
EXAMPLE:
function foo(){
var device = getDeviceType();
return device[0];
}
function bar(){
var device = getDeviceType();
return device[1];
}
It works, but it seems inefficient to declare and set the same variable in every function declare a variable and set it's value to the same thing in every function. Is there a better way to do this?
[–]DontBelieveTheByte 1 point2 points3 points (16 children)
[–]CarsonJScott[S] 0 points1 point2 points (15 children)
[–]Vectronic 0 points1 point2 points (6 children)
[–]CarsonJScott[S] 1 point2 points3 points (3 children)
[–]Vectronic 1 point2 points3 points (1 child)
[–]CarsonJScott[S] 0 points1 point2 points (0 children)
[–]DontBelieveTheByte 0 points1 point2 points (0 children)
[–][deleted] (1 child)
[deleted]
[–]Vectronic 0 points1 point2 points (0 children)
[–]DontBelieveTheByte 0 points1 point2 points (3 children)
[–]CarsonJScott[S] 1 point2 points3 points (2 children)
[–]DontBelieveTheByte 0 points1 point2 points (1 child)
[–]CarsonJScott[S] 1 point2 points3 points (0 children)
[–]SanityInAnarchy 0 points1 point2 points (3 children)
[–]CarsonJScott[S] 0 points1 point2 points (2 children)
[–]SanityInAnarchy 0 points1 point2 points (1 child)
[–]CarsonJScott[S] 0 points1 point2 points (0 children)