[Javascript] exists() method

Troy III Ajnej trojani2000 at hotmail.com
Wed Nov 23 15:10:31 CST 2011


 If you'd need to use "isDefined" code for
 "exists" test\s only. -You can. -A quick fix is
 to take the:

 isDefined=
 function(x){try{return eval(x)}catch(e){return!1}}


 and modify it into a boolean "exists" test method
 like this:


 exists=
 function(x){try{return eval(x),!0}catch(e){return!1}}


 Warning: x becomes a temporarily 'reserved'
 word here!


 alert( exists('x') ) // -->always: true.


 its a super(arg:val:lit)match paradox situation.

 We can't test against a single x anymore because x
 is a local variable of the current function passed
 as fn arg "x" after being read by eval, and since
 fn return will always look-around before it looks
 up, it will see it and will pass it as a string
 literal "x" which naturally will evaluate as "true";
 in other words:
 -instead of "that.x", it will return "this.x"!


 Let's fix the 'this' than.
 we'll have to burry the "this" voodoo child context
 1 level deeper - so we can buy our way out of this
 paradox in exchange for another 2 extra bytes.


 ---------------------------8<---------------------------
 exists=
 /*b.b. Troy III p.a.e.*/
 function(x){try{return!!(0,eval)(x)}catch(e){return!1}}
 --------------------------->8---------------------------


 The voodoo-chain is now broken, Mr. "x" is free again.
 The host method doesn't have access to our private x
 anymore. And we will not get this x-ray false positive
 leak exception again. The Lab is secure.


 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Troy III
       progressive art enterprise
 ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ 		 	   		  


More information about the Javascript mailing list