Showing posts with label global-variables. Show all posts
Showing posts with label global-variables. Show all posts

Thursday, May 10, 2012

Why does a function declaration override non-writable properties of the global object?


Setting a property descriptor like this:




Object.defineProperty(window, 'someFunction', {
value: function() { alert('safe'); },
writable: false,
enumerable: false,
configurable: false
});

Require an arbitrary PHP file without leaking variables into scope


Is it possible in PHP to require an arbitrary file without leaking any variables from the current scope into the required file's variable namespace or polluting the global variable scope?

Sunday, April 8, 2012

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

Wednesday, March 7, 2012

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"]));
}

Tuesday, January 31, 2012

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){
...
}
}

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){
...
}
}