Hi,
I'm making an AJAX call to load prototype.js
I then call eval on the request's response text ie
success: function(req){
eval(req.responseText)
}
This works to load most javascript, but prototype in particular is
confusing me. This error is getting thrown:
Node has no properties
by the following prototype source (line 1526):
if (!window.Node) var Node = { };
if (!Node.ELEMENT_NODE) {
Debug statements immediately before this section show
window.Node != null
Node == null
As far as I understand javascript that should be impossible since
window.Node == Node as long as you're operating at the base level name
space, ie window, not in a function etc.
Obviously none of these shenanigans show up when I load prototype
normally with a script tag. Is it really possible that eval is
behaving differently than the javascript interpreter? Isn't it just a
hook into the javascript interpreter?
Thanks for the help, this is driving me nuts with curiosity!
Carl
on 2008-06-26 22:34
on 2008-06-26 22:38
Yes, eval() is a hook into the interpreter - BUT, since you're doing
your
eval() in the context of an Ajax callback, all the outer variable
assignments will define variables local to that function! So,
definitely
will not work:
function() {
eval("var x = 42");
}
x === undefined!
eval("var x = 42");
x === 42
-Fred
On Thu, Jun 26, 2008 at 3:33 PM, dcx <Youngblood.Carl@gmail.com> wrote:
> Obviously none of these shenanigans show up when I load prototype
> normally with a script tag. Is it really possible that eval is
> behaving differently than the javascript interpreter? Isn't it just a
> hook into the javascript interpreter?
>
> Thanks for the help, this is driving me nuts with curiosity!
--
Science answers questions; philosophy questions answers.
on 2008-06-26 22:38
Oops: more explicit here:
function f() {
eval("var x = 42");
}
f();
x === undefined
On Thu, Jun 26, 2008 at 3:37 PM, Frederick Polgardy <fred@polgardy.com>
wrote:
>
>> normally with a script tag. Is it really possible that eval is
>> behaving differently than the javascript interpreter? Isn't it just a
>> hook into the javascript interpreter?
>>
>> Thanks for the help, this is driving me nuts with curiosity!
>
>
> --
> Science answers questions; philosophy questions answers.
--
Science answers questions; philosophy questions answers.