...

View Full Version : Need explanation on possible scope issue



blaze4218
03-21-2012, 05:28 PM
I have devised the following constructor based loosely on the observer pattern


Observer = function (ConditionIsTrue , codeToExecute){

var
observer = this ,
ConditionWasMet = false ,

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};

Loop.call(observer , CheckIfReady)
observer.speed(1)

};

It works fine, no problems that I know of...

But the most interesting thing happened when I attached it to my lib and ran it through the http://closure-compiler.appspot.com/home compiler


$['Observer'] = function (//...etc...
For the first time the compiler has added something to my global scope


var i=!1;
window.$=function(){//...etc...
...
Observer:function(j,k){var h=i;Loop.call(this,function(){j()?(h||k(),h=!0):h&&(h=i)});this.speed(1)}
}
})();

Can someone explain to me why the var ConditionWasMet had to be exported to the global scope?
Was it already in the global scope? That would confuse me considering the observer can be called from multiple instances without conflict...
But I don't want any surprise conflicts jumping out at me later, I appreciate the consideration.

DaveyErwin
03-21-2012, 05:54 PM
the most interesting thing happened when I attached it to my lib and ran it through the http://closure-compiler.appspot.com/home compiler

Can someone explain to me why the var ConditionWasMet had to be exported to the global scope?


Why not show the code that
you "ran it through the http://closure-compiler.appspot.com/home compiler"

blaze4218
03-21-2012, 06:44 PM
well...
the whole code is considerably larger in size,
the relevant code is here (I tried this and other variations which all met the same fate),
the actual output of the compiler was in my post, save 1 renamed variable for brevity,
I have successfully narrowed the generation of the exported global variable to ConditionWasMet via trial and error (removing the lines ConditionWasMet = true; and if (ConditionWasMet) ConditionWasMet = false; removed the global var),
many contributors here shun posting irrelevant code...

But if you think it will help


window["BW"] = function() {
"use strict";

var Loop = function(myFunct) {
"Private"; var
loop = this ,
rate = 1E3 ,
code = myFunct ,
paused = false ,
run = function() {
clearTimeout(loop.Cycle);
if(code) {
if(!paused) {
code()
}
loop.Cycle = setTimeout(run , rate)
}
};
"Public";
loop["resume"] = function() {
paused = false;
} ,
loop["pause"] = function() {
paused = true;
} ,
loop["die"] = function() {
code = false;
} ,
loop["speed"] = function(r) {
r && typeof r == "number" && r > 0 && (rate = r);
return rate;
} ,
loop["init"] = function() {
if(!loop.Cycle && code) {
run();
}
}
} ,
ID = function(e) {
return"object" === typeof e ? e : document.getElementById(e);
} ,
CSS = function(e) {
if(!ID(e)) {
return false;
}
return ID(e).style;
} ,
HTML = function(e , s , q) {
var tmp;
q ? (tmp = document.createElement("div") , tmp.innerHTML = s , ID(e).appendChild(tmp)) : ID(e).innerHTML = s;
} ,
AddSpace = function(b) {
var s = "";
for(var i = 0;i < b;++i) {
s += "&nbsp;"
}
return s;
} ,
Strip = function(e) {
ID(e).innerHTML = ID(e).innerHTML.replace(/\s*</gi , "<");
} ,
Clean = function() {
return{
"Alpha":function(v) {
return v.replace(/[^a-zA-Z]/g , "");
} ,
"Numeric":function(v) {
return v.replace(/[^0-9]/g , "");
} ,
"AlphaNumeric":function(v) {
return v.replace(/[^0-9a-zA-Z]/g , "");
} ,
"Email":function(v) {
}
}
}() ,
Time = function() {
return new Date;
} ,
AssertArr = function(a) {
return isArray(a) ? a : [a];
} ,
GetClass = function(c) {
var a =
d =
b = [];
a = document.getElementsByTagName("*");
for(var i = 0;i < a.length;++i) {
b = a[i].className.split(" ");
for(var j = 0;j < b.length;++j) {
b[j] == c && d.push(a[i]);
}
}
return d;
} ,
AddClass = function(id , newClass) {
var existingClasses = [] ,
AllId = AssertArr(id);

for(var i = 0;i < AllId.length;++i) {
var id = ID(AllId[i]);
existingClasses = id.className.split(" ");
for(var j = 0;j < existingClasses.length;++j) {
if(existingClasses[j] == newClass) {
return;
}
}
existingClasses.push(newClass);
id.className = existingClasses.join(" ");
}
} ,
RemoveClass = function(id , oldClass) {
var existingClasses = [];
AllId = AssertArr(id);

for(var i = 0;i < AllId.length;++i) {
var id = ID(AllId[i]);
if(!id) {
continue;
}

existingClasses = id.className.split(" ");

for(var j = 0;j < existingClasses.length;++j) {
if(existingClasses[j] == oldClass) {
existingClasses.splice(j , 1);
}
}

id.className = existingClasses.join(" ");
}
} ,
ClassApply = function(className , a) {
var className = AssertArr(className);

for(var i = 0;i < className.length;++i) {
var myClass = GetClass(className[i]);
if(!myClass) {
continue;
}

if(a.trigger) {
for(var j = 0;j < myClass.length;++j) {
myClass[j][a.trigger] = a.action;
}
}
else {
for(j = 0;j < myClass.length;++j) {
a.action.apply(myClass[j]);
}
}

}
} ,
Disable = function(element , trigger , replacementFunction) {
var element = AssertArr(element);

for(var i = 0;i < element.length;++i) {
var e = ID(element[i]);
if(!e) {
continue;
}
if(e["old" + trigger] && e["old" + trigger] != "null") {
continue;
}
if(typeof e[trigger] === "function") {
e["old" + trigger] = e[trigger];
}
if(e.href && (trigger == "onclick" || trigger == "ondbclick")) {
e.href = "javascript:void(0)";
}
if(replacementFunction) {
e[trigger] = replacementFunction;
}
else {
e[trigger] = function() {
return false;
}
}
}
} ,
Enable = function(element , trigger) {
var element = AssertArr(element);

for(var i = 0;i < element.length;++i) {
var e = ID(element[i]);
if(!e || !e["old" + trigger]) {
continue;
}
if(typeof e[trigger] === "function") {
e[trigger] = e["old" + trigger];
e["old" + trigger] = "null";
}
}

} ,
AssertStyle = function(e , o) {
var e = AssertArr(e);

for(var i = 0;i < e.length;++i) {
for(var j in o) {
if(!ID(e)) {
continue;
}
CSS(e[i])[j] = o[j];
}
}
} ,
Center = function() {
var center = this ,
X =
Y = [] ,
Align = function() {
for(var i = 0;i < X.length;++i) {
var xPos = Math.floor(parseInt(ID(X[i]).parentNode.offsetWidth) / 2 - parseInt(ID(X[i]).offsetWidth) / 2);
CSS(X[i]).left = xPos > 0 ? xPos + "px" : "0px";
}
for(var i = 0;i < Y.length;++i) {
var yPos = Math.floor(parseInt(ID(Y[i]).parentNode.offsetHeight) / 2 - parseInt(ID(Y[i]).offsetHeight) / 2);
CSS(Y[i]).top = yPos > 0 ? yPos + "px" : "0px";
}
};

Loop.call(center , Align);
center.init();

return{
"X":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
X.push(e);
} ,
"Y":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
Y.push(e);
} ,
"XY":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
X.push(e) , Y.push(e);
}
}
}() ,
Observer = function(ConditionIsTrue , codeToExecute) {
"Private";var
observer = this ,
ConditionWasMet = false ,
CheckIfReady = function() {
if(ConditionIsTrue()) {
if(!ConditionWasMet) {
codeToExecute();
}
ConditionWasMet = true;
}
else {
if(ConditionWasMet) {
ConditionWasMet = false;
}
}
};

Loop.call(observer , CheckIfReady);
observer.speed(1);

} ,
Clone = function(a) {
if(null == a || "object" != typeof a) {
return[];
}
var c = a.constructor() , b;
for(b in a) {
a.hasOwnProperty(b) && (c[b] = a[b]);
}
return c;
} ,
CloneArray = function(b) {
for(var c = [] , a = 0;a < b.length;++a) {
c.push(b[a]);
}
return c;
} ,
isArray = function(o) {
return Object.prototype.toString.call(o) === "[object Array]";
};
Time["getFromSeconds"] = function(secs) {
time = [0 , 0 , secs];
for(var i = 2;i > 0;i--) {
time[i - 1] = Math.floor(time[i] / 60);
time[i] = time[i] % 60;
if(time[i] < 10) {
time[i] = "0" + time[i];
}
}
return time.join(":");
};
return{
"HTML":HTML ,
"CSS":CSS ,
"ID":ID ,
"S":AddSpace ,
"isArray":isArray ,
"Strip":Strip ,
"Center":Center ,
"Clean":Clean ,
"Time":Time ,
"GetClass":GetClass ,
"AddClass":AddClass ,
"RemoveClass":RemoveClass ,
"ClassApply":ClassApply ,
"Disable":Disable ,
"Enable":Enable ,
"Clone":Clone ,
"CloneArray":CloneArray ,
"Observer":Observer ,
"Loop":Loop ,
"$":AssertStyle
};
}();

DaveyErwin
03-21-2012, 07:09 PM
I put that in
http://closure-compiler.appspot.com/home
and got no errors
(only some warnings about useless code)

blaze4218
03-21-2012, 07:16 PM
not errors


It works fine, no problems that I know of...

For the first time the compiler has added something to my global scope

Can someone explain to me why the var ConditionWasMet had to be exported to the global scope?

I have put much effort into encapsulating my entire library, and don't quite understand why the compiler felt the need to export that variable, something it has never done before.

My only guess would be that it perceived it to be a global variable, and defined it in the "appropriate" scope... but why would it have that perception? Did I fail to localize the variable?

DaveyErwin
03-21-2012, 08:10 PM
I have devised the following constructor based loosely on the observer pattern


Observer = function (ConditionIsTrue , codeToExecute){

var
observer = this ,
ConditionWasMet = false ,

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};

Loop.call(observer , CheckIfReady)
observer.speed(1)

};

It works fine, no problems that I know of...

But the most interesting thing happened when I attached it to my lib and ran it through the http://closure-compiler.appspot.com/home compiler


$['Observer'] = function (//...etc...
For the first time the compiler has added something to my global scope


var i=!1;
window.$=function(){//...etc...
...
Observer:function(j,k){var h=i;Loop.call(this,function(){j()?(h||k(),h=!0):h&&(h=i)});this.speed(1)}
}
})();

Can someone explain to me why the var ConditionWasMet had to be exported to the global scope?
Was it already in the global scope? That would confuse me considering the observer can be called from multiple instances without conflict...
But I don't want any surprise conflicts jumping out at me later, I appreciate the consideration.

I can't find any of the above
code in the code below ?




well...
the whole code is considerably larger in size,
the relevant code is here (I tried this and other variations which all met the same fate),
the actual output of the compiler was in my post, save 1 renamed variable for brevity,
I have successfully narrowed the generation of the exported global variable to ConditionWasMet via trial and error (removing the lines ConditionWasMet = true; and if (ConditionWasMet) ConditionWasMet = false; removed the global var),
many contributors here shun posting irrelevant code...

But if you think it will help


window["BW"] = function() {
"use strict";

var Loop = function(myFunct) {
"Private"; var
loop = this ,
rate = 1E3 ,
code = myFunct ,
paused = false ,
run = function() {
clearTimeout(loop.Cycle);
if(code) {
if(!paused) {
code()
}
loop.Cycle = setTimeout(run , rate)
}
};
"Public";
loop["resume"] = function() {
paused = false;
} ,
loop["pause"] = function() {
paused = true;
} ,
loop["die"] = function() {
code = false;
} ,
loop["speed"] = function(r) {
r && typeof r == "number" && r > 0 && (rate = r);
return rate;
} ,
loop["init"] = function() {
if(!loop.Cycle && code) {
run();
}
}
} ,
ID = function(e) {
return"object" === typeof e ? e : document.getElementById(e);
} ,
CSS = function(e) {
if(!ID(e)) {
return false;
}
return ID(e).style;
} ,
HTML = function(e , s , q) {
var tmp;
q ? (tmp = document.createElement("div") , tmp.innerHTML = s , ID(e).appendChild(tmp)) : ID(e).innerHTML = s;
} ,
AddSpace = function(b) {
var s = "";
for(var i = 0;i < b;++i) {
s += "&nbsp;"
}
return s;
} ,
Strip = function(e) {
ID(e).innerHTML = ID(e).innerHTML.replace(/\s*</gi , "<");
} ,
Clean = function() {
return{
"Alpha":function(v) {
return v.replace(/[^a-zA-Z]/g , "");
} ,
"Numeric":function(v) {
return v.replace(/[^0-9]/g , "");
} ,
"AlphaNumeric":function(v) {
return v.replace(/[^0-9a-zA-Z]/g , "");
} ,
"Email":function(v) {
}
}
}() ,
Time = function() {
return new Date;
} ,
AssertArr = function(a) {
return isArray(a) ? a : [a];
} ,
GetClass = function(c) {
var a =
d =
b = [];
a = document.getElementsByTagName("*");
for(var i = 0;i < a.length;++i) {
b = a[i].className.split(" ");
for(var j = 0;j < b.length;++j) {
b[j] == c && d.push(a[i]);
}
}
return d;
} ,
AddClass = function(id , newClass) {
var existingClasses = [] ,
AllId = AssertArr(id);

for(var i = 0;i < AllId.length;++i) {
var id = ID(AllId[i]);
existingClasses = id.className.split(" ");
for(var j = 0;j < existingClasses.length;++j) {
if(existingClasses[j] == newClass) {
return;
}
}
existingClasses.push(newClass);
id.className = existingClasses.join(" ");
}
} ,
RemoveClass = function(id , oldClass) {
var existingClasses = [];
AllId = AssertArr(id);

for(var i = 0;i < AllId.length;++i) {
var id = ID(AllId[i]);
if(!id) {
continue;
}

existingClasses = id.className.split(" ");

for(var j = 0;j < existingClasses.length;++j) {
if(existingClasses[j] == oldClass) {
existingClasses.splice(j , 1);
}
}

id.className = existingClasses.join(" ");
}
} ,
ClassApply = function(className , a) {
var className = AssertArr(className);

for(var i = 0;i < className.length;++i) {
var myClass = GetClass(className[i]);
if(!myClass) {
continue;
}

if(a.trigger) {
for(var j = 0;j < myClass.length;++j) {
myClass[j][a.trigger] = a.action;
}
}
else {
for(j = 0;j < myClass.length;++j) {
a.action.apply(myClass[j]);
}
}

}
} ,
Disable = function(element , trigger , replacementFunction) {
var element = AssertArr(element);

for(var i = 0;i < element.length;++i) {
var e = ID(element[i]);
if(!e) {
continue;
}
if(e["old" + trigger] && e["old" + trigger] != "null") {
continue;
}
if(typeof e[trigger] === "function") {
e["old" + trigger] = e[trigger];
}
if(e.href && (trigger == "onclick" || trigger == "ondbclick")) {
e.href = "javascript:void(0)";
}
if(replacementFunction) {
e[trigger] = replacementFunction;
}
else {
e[trigger] = function() {
return false;
}
}
}
} ,
Enable = function(element , trigger) {
var element = AssertArr(element);

for(var i = 0;i < element.length;++i) {
var e = ID(element[i]);
if(!e || !e["old" + trigger]) {
continue;
}
if(typeof e[trigger] === "function") {
e[trigger] = e["old" + trigger];
e["old" + trigger] = "null";
}
}

} ,
AssertStyle = function(e , o) {
var e = AssertArr(e);

for(var i = 0;i < e.length;++i) {
for(var j in o) {
if(!ID(e)) {
continue;
}
CSS(e[i])[j] = o[j];
}
}
} ,
Center = function() {
var center = this ,
X =
Y = [] ,
Align = function() {
for(var i = 0;i < X.length;++i) {
var xPos = Math.floor(parseInt(ID(X[i]).parentNode.offsetWidth) / 2 - parseInt(ID(X[i]).offsetWidth) / 2);
CSS(X[i]).left = xPos > 0 ? xPos + "px" : "0px";
}
for(var i = 0;i < Y.length;++i) {
var yPos = Math.floor(parseInt(ID(Y[i]).parentNode.offsetHeight) / 2 - parseInt(ID(Y[i]).offsetHeight) / 2);
CSS(Y[i]).top = yPos > 0 ? yPos + "px" : "0px";
}
};

Loop.call(center , Align);
center.init();

return{
"X":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
X.push(e);
} ,
"Y":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
Y.push(e);
} ,
"XY":function(e) {
if(!CSS(e).position) {
AssertStyle(e , {"position":"relative"});
}
X.push(e) , Y.push(e);
}
}
}() ,
Observer = function(ConditionIsTrue , codeToExecute) {
"Private";var
observer = this ,
ConditionWasMet = false ,
CheckIfReady = function() {
if(ConditionIsTrue()) {
if(!ConditionWasMet) {
codeToExecute();
}
ConditionWasMet = true;
}
else {
if(ConditionWasMet) {
ConditionWasMet = false;
}
}
};

Loop.call(observer , CheckIfReady);
observer.speed(1);

} ,
Clone = function(a) {
if(null == a || "object" != typeof a) {
return[];
}
var c = a.constructor() , b;
for(b in a) {
a.hasOwnProperty(b) && (c[b] = a[b]);
}
return c;
} ,
CloneArray = function(b) {
for(var c = [] , a = 0;a < b.length;++a) {
c.push(b[a]);
}
return c;
} ,
isArray = function(o) {
return Object.prototype.toString.call(o) === "[object Array]";
};
Time["getFromSeconds"] = function(secs) {
time = [0 , 0 , secs];
for(var i = 2;i > 0;i--) {
time[i - 1] = Math.floor(time[i] / 60);
time[i] = time[i] % 60;
if(time[i] < 10) {
time[i] = "0" + time[i];
}
}
return time.join(":");
};
return{
"HTML":HTML ,
"CSS":CSS ,
"ID":ID ,
"S":AddSpace ,
"isArray":isArray ,
"Strip":Strip ,
"Center":Center ,
"Clean":Clean ,
"Time":Time ,
"GetClass":GetClass ,
"AddClass":AddClass ,
"RemoveClass":RemoveClass ,
"ClassApply":ClassApply ,
"Disable":Disable ,
"Enable":Enable ,
"Clone":Clone ,
"CloneArray":CloneArray ,
"Observer":Observer ,
"Loop":Loop ,
"$":AssertStyle
};
}();


Maybe post the code that
causes you concern.

blaze4218
03-21-2012, 09:10 PM
well, now we are just going in circles...

post the code that
causes you concern.
the code that concerns me is in post #1, as is the out put that I question...

I have edited post #2 highlighting the code from post #1 in blue, the lines that cause the mysterious var j=!1; are highlighted in red. Commenting the red lines will result in a fully encapsulated BW object to which I am accustomed.

To satisfy your request even further I have tried to recreate the output with only the relevant crossection of my lib

window["BW"] = function() {
var Loop = function(myFunct) {
"Private";
var loop = this, rate = 1E3, code = myFunct, paused = false, run = function() {
clearTimeout(loop.Cycle);
if(code) {
if(!paused) {
code()
}
loop.Cycle = setTimeout(run, rate)
}
};
"Public";
loop["resume"] = function() {
paused = false
}, loop["pause"] = function() {
paused = true
}, loop["die"] = function() {
code = false
}, loop["speed"] = function(r) {
r && typeof r == "number" && r > 0 && (rate = r);
return rate
}, loop["init"] = function() {
if(!loop.Cycle && code) {
run()
}
}
}, Observer = function(ConditionIsTrue, codeToExecute) {
"Private";
var observer = this, ConditionWasMet = false, CheckIfReady = function() {
if(ConditionIsTrue()) {
if(!ConditionWasMet) {
codeToExecute()
}
ConditionWasMet = true
}else {
if(ConditionWasMet) {
ConditionWasMet = false
}
}
};
Loop.call(observer, CheckIfReady);
observer.speed(1)
};
return{"Loop":Loop, "Observer":Observer}
}(); and that did not reproduce the bizarre line var j=!1;

I think the question is simpler than my first post has led you to believe...

Q:
Is there anything in my Observer object that exists in the global scope?

DaveyErwin
03-21-2012, 11:45 PM
I think the question is simpler than my first post has led you to believe...

Q:
Is there anything in my Observer object that exists in the global scope?


<script>

function Loop(){CheckIfReady()}
function ConditionIsTrue(){return true}
function codeToExecute(){return true}
Observer = function (ConditionIsTrue , codeToExecute){

var
observer = this ,
ConditionWasMet = false

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};



Loop.call(observer , CheckIfReady)
//observer.speed(1)

};
a = new Observer(ConditionIsTrue , codeToExecute);

alert(CheckIfReady)


</script>

rnd me
03-21-2012, 11:48 PM
this===window by default...

DaveyErwin
03-22-2012, 02:18 PM
this===window by default...


<script>
function Loop(){CheckIfReady()}
function ConditionIsTruefn(){return true}
function codeToExecutefn(){return true}
Observer = function (ConditionIsTrue , codeToExecute){
var
observer = this ,
ConditionWasMet = false

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};
Loop.call(observer , CheckIfReady)
//observer.speed(1)
alert(window == observer)// alerts false
};
a = new Observer(ConditionIsTruefn , codeToExecutefn);
</script>

Mikebert4
03-22-2012, 03:08 PM
Observer = function (ConditionIsTrue , codeToExecute){

var
observer = this ,
ConditionWasMet = false

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};



Loop.call(observer , CheckIfReady)
//observer.speed(1)

};
a = new Observer(ConditionIsTrue , codeToExecute);

alert(CheckIfReady)






You don't initialise CheckIfReady in the local scope (ie: in the scope of Observer). Now, you'd have through this would have thrown an undefined error, but it looks like your compiler has gotten around that by initialising it in the global scope...

In real terms:



CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};


Should be:



var CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};



Is that the issue? Or am I reading the above all wrong?

M

blaze4218
03-22-2012, 03:55 PM
<script>

function Loop(){CheckIfReady()}
function ConditionIsTrue(){return true}
function codeToExecute(){return true}
Observer = function (ConditionIsTrue , codeToExecute){

var
observer = this ,
ConditionWasMet = false , // <-Your missing a very important comma...

CheckIfReady = function () {

if (ConditionIsTrue()) {

if(!ConditionWasMet)
codeToExecute();

ConditionWasMet = true;

}
else {
if (ConditionWasMet) ConditionWasMet = false;
}
};



Loop.call(observer , CheckIfReady)
//observer.speed(1)

};
a = new Observer(ConditionIsTrue , codeToExecute);

alert(CheckIfReady)


</script>
your alert() (and Loop function) will fail. That comma that you removed ended the series of local variable declarations...
I do get your point that I should test ConditionWasMet in the global scope to see if it exists there. I used the same alert method that you used in your test, and it was undefined as it should be! I am stumped as to why the compiler would have initialized this variable in the global scope!

@rnd_me by default yes, but it changes with scope. (that's the main reason i alias it to a variable first off so that I don't loose track of the scope of the object I am referencing. Also the variable reference will be rewritten as a single character by closure-compiler, allowing for greater minification when called more than 3 times for a single object)

@Mikebert4 that's a good point, but it's not in any of the code I posted. Only in DaveyErwins and yours.
Also, it is ConditionWasMet that has been moved to the global scope

Mikebert4
03-22-2012, 04:51 PM
Ahh, my apologies for misreading...

In which case, I'm as stumped as you are - I can't see why it would feel the need to move it to global. :confused:



EZ Archive Ads Plugin for vBulletin Copyright 2006 Computer Help Forum