[Javascript] [solved ]Object Not Defined "isDefined" & "readFrom "method

Troy III Ajnej trojani2000 at hotmail.com
Mon Nov 21 16:32:10 CST 2011


*Your error - not Safari's* - no need to dupe it.

Arguments of the function should be passed as strings - not as an already established fact of an arbitrarily 
existing object!

You are presuming  that a.b.c.d.e.f object exists without any doubt;
Than, for what reason would you be using the "isDefined" method anyway?!

[No it shouldn't return a "boolean", that not the issue. My original "isDefined" returns
boolean -but now I see - that it's not pragmatic and weakens the code efficiency when
using it. ]

No function can receive an undefined argument without causing an error;
you can't .getlEmentById( title );  -  you need to, either pass it as a string literal,
or (in this case) a string object. 'No alternative.

There's no way you can pass a chain of some plain symbols as a function argument.



The correct syntax is:

   isDefined( "a.b.c.d.e.f" );
Cheers, if you've already acknowledged it.
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Troy III
progressive art enterprise
~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~


----------------------------------------
> From: riegel at clearimageonline.com
> Date: Mon, 21 Nov 2011 16:28:22 -0500
> To: javascript at lists.evolt.org
> Subject: Re: [Javascript] [solved ]Object Not Defined "isDefined" & "read>From "method
>
> Troy,
>
> As I think about it "isDefined" should return a boolean. Your function doesn't do that and it returns an error in Safari
>
> Try this to duplicate it from the console...
>
>
> > isDefined=function(x){try{return eval(x)}catch(e){return!1}}
> > isDefined(a.b.c.d.e.f)
>
> It doesn't return a boolean but throws an error. Also I wonder if there is a way to avoid using eval for this type of thing. Seems like it could be a security risk to fire up eval() just to see if something exists.
>
> I will fiddle with it a bit to see if there might be another route.
>
> Thanks,
>
> Terry
>
>
> On Nov 21, 2011, at 2:17 PM, Troy III Ajnej wrote:
>
> >
> >
> >
> > isDefined
> > ---------------------------8<------------------------------------------
> > /* b.b. Troy III p.a.e. */
> > isDefined=function(x){try{return eval(x)}catch(e){return!1}}
> > --------------------------->8------------------------------------------
> >
> > readFrom
> > -------------------------8<--------------------------------------------
> > /* b.b. Troy III p.a.e. */
> > readFrom=function(x,y){return isDefined(x)||y}
> > ------------------------->8--------------------------------------------
> >
> > usage
> > -------------------------8<--------------------------------------------
> > title=readFrom("a.b.c.d.e.f.g.h.i.j.k.title", "untitled");alert(title);
> >
> > [element].innerText=readFrom("a.b.c.d.e.f.g.h.i.j.k.title", "untitled");
> > -------------------------->8-------------------------------------------
> >
> > p.s.:
> > sorry about the mess, I'm posting from Chrome[!?!]. Let's see...
> >
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> > Troy III
> > progressive art enterprise
> > ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> >
> >
> >
> >
> > _______________________________________________
> > Javascript mailing list
> > Javascript at lists.evolt.org
> > http://lists.evolt.org/mailman/listinfo/javascript
>
> Terry Riegel
>
> Put Your TimeClock on the Web
> http://www.punchedin.com
>
> _______________________________________________
> Javascript mailing list
> Javascript at lists.evolt.org
> http://lists.evolt.org/mailman/listinfo/javascript
 		 	   		  


More information about the Javascript mailing list