Skip to main content

Posts

Showing posts with the label global-variables

Should I use window.variable or var?

We have a lot of setup JS code that defines panels, buttons, etc that will be used in many other JS files. Typically, we do something like: grid.js var myGrid = ..... combos.js var myCombo = ..... Then, in our application code, we: application.js function blah() { myGrid.someMethod() } someother.js function foo() { myCombo.someMethod(); myGrid.someMethod(); } So, should we be using the var myGrid or is better to use window.myGrid What's the difference? Source: Tips4all

Bug or hack? $GLOBALS

$GLOBALS["items"] = array('one', 'two', 'three', 'four', 'five' ,'six', 'seven'); $alter = &$GLOBALS["items"]; // Comment this line foreach($GLOBALS["items"] as $item) { echo get_item_id(); } function get_item_id(){ var_dump(key($GLOBALS["items"])); } Check output of this code, with commented and uncommented second line. My result(PHP 5.3.0). With second line int(1) int(2) int(3) int(4) int(5) int(6) NULL Without second line: int(1) int(1) int(1) int(1) int(1) int(1) int(1) Why so strange result?

how to use global variable with phonegap navigator.notification.confirm?

i have this situation: <a href="#" onClick="submitNotification(1);">click1</a> <a href="#" onClick="submitNotification(2);">click2</a> <a href="#" onClick="submitNotification(3);">click3</a> function submitNotification(cdata){ navigator.notification.confirm( 'do you like '+cdata+' option ', submit, 'notice', 'Yes,No' ); function submit(button){ if (button == 1){ alert(id); //or alert(cdata); } else if (button == 2){ ... } } so, i click on a link, 1 or 2 ... gets send to submitNotification where i get a message: do you like 1 option or do you like 2 option or ... depending on what link i click. this function calls submitVote and sends button var to it somehow. yes means 1 and no means 2 . the problem is that i cant get id or cdata from the original link.

how to use global variable with phonegap navigator.notification.confirm?

i have this situation: <a href="#" onClick="submitNotification(1);">click1</a> <a href="#" onClick="submitNotification(2);">click2</a> <a href="#" onClick="submitNotification(3);">click3</a> function submitNotification(cdata){ navigator.notification.confirm( 'do you like '+cdata+' option ', submit, 'notice', 'Yes,No' ); function submit(button){ if (button == 1){ alert(id); //or alert(cdata); } else if (button == 2){ ... } } so, i click on a link, 1 or 2 ... gets send to submitNotification where i get a message: do you like 1 option or do you like 2 option or ... depending on what link i click. this function calls submitVote and sends button var to it somehow. yes means 1 and no means 2 . the problem is that i cant get id or cdata from the original link.