[Javascript] Object Not Defined

Troy III Ajnej trojani2000 at hotmail.com
Sat Nov 19 20:58:44 CST 2011


Hi one thing I don't understand is why are you returning an (object by default) instead of (one would expect) a boolean, -logically a false one!But that's probably because of your sepcific algo requirements there. For this part of an a conditional:>  if(a && a.data && a.data.items){  I presume that this :if (typeof a!='undefined'){return a.data||[]...
would do just fine.  You can however write a ternary assignment if you like:  var zeeData = (typeof a!='undefined') ? a.data.items||a.data:[] or you can also have a function + arguments working their ass for you: function(a, data, item ){              return( typeof a != 'undefined' ) ? a[data][item] || a[data] || [] : [];}
 !This will retrieve an altrenative, in case a.data.item is not presentyou will recieve the "a.data" content instead of empty [] if it exists, or if that's not of any (I presume) practical use for you, -you can: function(a, data, item ){              return( typeof a != 'undefined' ) ? a[data] ? a[data][item] : [] : [];}
Or perhaps: function zeeData(a, data, items ){
 return( typeof a & a[data] != 'undefined' ) ? a[data][items] || [] : [ ];
 }
since if I understood it well - you are targeting the third row,this would be a better choice, or my final thought on this turn I guess. 
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
                Troy III
       progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
 > From: riegel at clearimageonline.com
> Date: Fri, 11 Nov 2011 07:45:07 -0500
> To: javascript at lists.evolt.org
> Subject: [Javascript]  Object Not Defined
> 
> Hello All,
> 
> I am looking for a better way for the following piece of code...
> 
> function(a){
>  if(a && a.data && a.data.items){
>   return a.data.items;}
>  else{
>   return[];
>  }
> }
> 
> It would be nice if this did the same thing...
> 
> function(a){return a.data.items || []};
> 
> Anyone have any thought on how this could be done I wouldn't mind wrapping it into a function if that helped. Something like this possibly...
> 
> 
> function(a){return or(a.data.items,[]) };
> 
> 
> Thanks for any help.
> 
> Terry
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
 		 	   		  


More information about the Javascript mailing list