WebKit Bugzilla
New
Browse
Log In
×
Sign in with GitHub
or
Remember my login
Create Account
·
Forgot Password
Forgotten password account recovery
RESOLVED INVALID
14102
eval() to create an anonymous function.
https://bugs.webkit.org/show_bug.cgi?id=14102
Summary
eval() to create an anonymous function.
Gregory Nacu
Reported
2007-06-12 13:38:44 PDT
In previous versions of Safari, and in Firefox I've used (sparingly, and seemingly necessary) an eval() to create an anonymous function that references the object creating the function, then it attaches that anonymous function to the onclick of some other element on the page. In the 2007-06-12 build of WebKit and in Safari 3 beta, if you eval('function() {alert("test")};') you get a parse error on "line 1"
Attachments
Add attachment
proposed patch, testcase, etc.
Geoffrey Garen
Comment 1
2007-06-12 14:04:22 PDT
This is correct behavior. A stand-alone nameless function expression is a syntax error because it's unclear whether the statement is a function expression or a function definition. The simplest solution is to surround your function expression with parentheses, like so: eval('(function() { alert("test"); })');
Geoffrey Garen
Comment 2
2007-06-12 14:04:49 PDT
This behavior matches IE6, too.
Note
You need to
log in
before you can comment on or make changes to this bug.
Top of Page
Format For Printing
XML
Clone This Bug