- Code: Select all
var _gi = [];
function getInfo(x,y,com){
if(typeof _gi[x] !== 'undefined'
&& typeof _gi[x][y] !== 'undefined' // <-- here error
&& typeof _gi[x][y][com] !== 'undefined') { //...code here }
}else{
return _gi[x][y][com];
}
}
Error like "TypeError: Result of expression '_gi[x]' [undefined] is not an object.", i create test file on nodejs and it's work like a charm:
- Code: Select all
#!/usr/bin/js
var ref = 100; // How many m.seconds do we remember
var _gi = [];
function getInfo(x,y,com){
if(typeof _gi[x] !== 'undefined'
&& typeof _gi[x][y] !== 'undefined'
&& typeof _gi[x][y][com] !== 'undefined'
&& _gi[x][y][com].time > (new Date().getTime()-ref)){
return _gi[x][y][com]; // We already know the answer, quickly returned
} else {
_gi[x] = [];
_gi[x][y] = new Object();
_gi[x][y][com] = new Object();
_gi[x][y][com].time = new Date().getTime();
for(var n=0;n<50000000;n++){;} // heavy-heavy code here
_gi[x][y][com].value = true;
console.log("getInfo(): populate/return");
return _gi[x][y][com];
}
}
for(var i = 0; i < 10000; i++) {
console.log(new Date().getTime()+": ", getInfo(2,3,"test"));
}
console.log(getInfo(2,3,"test").value);
I check the stackoverflow, and find answers: http://stackoverflow.com/questions/5134 ... javascript
The logic will return false if the first test returns false, and tests the second dimension only if the first one is true.
if(a[1] == undefined && a[1][2] == undefined)
Yeah, i do already this, and it work in nodejs, but in WZ this trick don't work.
I think in WZ javascript logic trying to compare all the passed variables in the "IF" directive..
What engine of js using in WZ ?