On Nov 14, 6:30 am, RobG <[EMAIL PROTECTED]> wrote:
> On Nov 14, 7:39 am, Ehsun <[EMAIL PROTECTED]> wrote:
>
> > I've create an Object in my pages script tags, something like this:
>
> > a = new A();
>
> > and when I want to call a method of a in the script which is actually
> > the ajax content (evaluated with .evalScripts) everything is fine. but
> > when the creation and the calling code, both are in the ajax contents
> > (seperate requests) which are evaluated! the second script (calling
> > script) has no access to the object!!!
>
> > What should I do?
>
> Using eval changes the execution context, the following might help
> explain:
>
> var a = 1, b = 2;
>
> function evalString(s) { eval(s); }
>
> alert(a == b);  // false
>
> evalString('var b = 1;');
> alert(a == b);  // false
>
> evalString('b = 1;');
> alert(a == b);  // true
>
> evalString('function foo(){alert("foo");}');
> try {
>   foo();} catch (e) {
>
>   alert(e);  // ReferenceError: foo is not defined
>
> }
>
> evalString('foo = function (){alert("foo");}');
> foo();  // foo
>
> There are work arounds, but best to avoid eval'ing scripts altogether.
>
> --
> Rob


So how can I send JavaScript code from the server to the client to be
executed if I should avoid it?
By the way, I don't eval scripts myself, I use the evalScripts method
of String class of Prototype.

--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups 
"Prototype & script.aculo.us" group.
To post to this group, send email to prototype-scriptaculous@googlegroups.com
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at 
http://groups.google.com/group/prototype-scriptaculous?hl=en
-~----------~----~----~----~------~----~------~--~---

Reply via email to