yes you are right

i wonder if theres a clever way round this ...



On Jul 27, 7:06 pm, "Michael Geary" <[EMAIL PROTECTED]> wrote:
> > > > From:weepy
>
> > > > $s = function(s) {
> > > >   p = s.replace(/#{/g, "' + eval(").replace(/}/g, ") + '")
> > > >   p = "'" + p + "'"
> > > >   return eval(p)
> > > > }
>
> > > > a="Jonah"
> > > > b=30
>
> > > > $s("#{a} is #{b} years old")
> > > >   ==> "Jonah is 30 years old"
> > > From: Michael Geary
> > > Sorry to be a party pooper, but what happens if you call $s from
> > > inside a function, using replacement variables that are
> > > local to that function? How will the "eval" see those variables?
> > From: Stephan Beal
> > You can, to the best of my knowledge, eval code created in
> > your local scope, referencing vars created in your scope.
>
> > For some details, see:
>
> >http://blog.zimki.com/tomi/2006/08/07/javascript-eval
>
> > "What the eval method does is evaluate the passed string as
> > JavaScript in the context of the Object upon which it is called."
>
> Right, that was exactly my point. The eval function is being called inside
> the $s function, so it won't see local variables in a different function.
> For example, this won't work:
>
>    function test() {
>       a = "Jonah";
>       b = 30;
>       alert( $s("#{a} is #{b} years old") );
>    }
>
> -Mike

Reply via email to