0

so i have some code which looks like this :

var my_important_var_x = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]

function checkmyresolutin() {
   // this tests the broswer/window resolution and print to the body [for css purposes]
  var resolution_is = '768px';
  my_important_var_x = resolution_is; // now the var contains the resolution

  return my_important_Var_X;
}

checkmyresolutin(); // for getting the resolutoin on document ready.

$(window).resize(function(){
   checkmyresolutin();  // this is the important part,every time the browser is resized i need to know ,certain function load/unload on certain resolutions.
});

function_abc(); // this is my problem,ill explain bellow,to keep this code block clean.

So after the checkmyresolutin() is called when the browser is resized and it returns the resolution/sceensize and is stored in the my_important_var_x variable ,i need to pass that latest information from that variable to the function_abc(); function...anyone ?

EDIT :

Guys,there are typos but ignore them,i did not copy paste my .js,becasuse it would take up to 400 lines,this is just an example ,the "logic" is what's important here.

I just need somehow to pass content of the enter code here to the function_abc() after the checkmyresolutin() has been run by the jQuery resize function()

lordZ3d
  • 540
  • 6
  • 20
  • I'm a bit confused. Right now you don't need to pass anything; the variable is a global. – Dave Newton Aug 08 '14 at 12:32
  • Just call `function_abc()` from the `resize` handler as well? – Bergi Aug 08 '14 at 12:36
  • 1
    `my_important_Var_X` -vs- `my_important_var_X` ? – Tim Vermaelen Aug 08 '14 at 12:36
  • @TimVermaelen typo...sorry – lordZ3d Aug 08 '14 at 13:02
  • @Bergi can't,must be like this. – lordZ3d Aug 08 '14 at 13:03
  • Sorry, the `resize` handler will run in the future. You just can't do that. You could of course create an event stream (that emits resolution events), and pass that to `function_abc`. – Bergi Aug 08 '14 at 13:13
  • @Aca85 You seem to be saying you want to pass the value to the function without calling the function - what would you expect that to do? – CupawnTae Aug 08 '14 at 13:16
  • Please don't tell us to ignore typos, but rather fix them. The better (easier to understand) your question is, the more likely we will help you. Incomprehensible, long-winded questions get downvoted and eventually closed. – Bergi Aug 08 '14 at 13:37

1 Answers1

0

You have a typo:

var my_important_var_x = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]

should be

var my_important_Var_X = 'init'; // my global variable for storing one very important piece of info. [screen size/resolution]

See this JSFiddle, with an annoying alert, to show it working.

I also made a different version where function_abc() is called automatically on resize, just to show how that works.

Check out this discussion of variable scope in Javascript.

Community
  • 1
  • 1
jimm101
  • 948
  • 1
  • 14
  • 36