On Nov 15, 4:56 am, "T.J. Crowder" <[EMAIL PROTECTED]> wrote:
> > Returning functions this way doesn't imply they do not have names. I've
> > successfully used pattern "return someNamed function(){ ... }" for
> > debugging.
>
> You mean "return function someNamed() { ... }", right? That's fine by
> the specs, because the FunctionExpression is allowed to have an
> optional name. (ECMA spec[1], section 13.)
>
> [1]http://www.ecma-international.org/publications/standards/Ecma-262.htm
If only it was that easy : )
I stopped using named expressions after finding out about IE bug (what
else is new, right?). IE actually does something very stupid. It
erroneously parses named FunctionExpression as *both*
FunctionExpression and FunctionDeclaration. As surprising as it might
sound, IE creates 2 Function objects and so we, ironically, end up
with even more memory clog : )
This issue is more known for its "scoping" problem - when IE exposes
named expression identifier to the enclosing scope (since it's a
FunctionDeclaration), but I think that consequences of creating more
functions than needed is equally bad (and is exactly why I'm trying to
avoid it lately).
You can find more examples/explanations of this bug in c.l.j archives
but a simple test describing the problem would be:
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN"
"http://www.w3.org/TR/html4/strict.dtd">
<html lang="en">
<head>
<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">
<title></title>
</head>
<body>
<script type="text/javascript">
(function(){
// this should produce undefined,
// as FunctionExpression's identifier (`foo`) should
// only be available to function body
// IE erroneously parses it as a FunctionDeclaration
document.write(foo + '<br>');
// create named FunctionExpression
var bar = (function foo(){
return bar === foo;
});
// foo simply compares Function object
// refered to by `foo` and Function object
// refered to by `bar`
// in IE it returns `false` -
// those are 2 different objects
document.write(foo());
})();
</script>
</body>
</html>
> --
> T.J. Crowder
> tj / crowder software / com
--
kangax
[...]
--~--~---------~--~----~------------~-------~--~----~
You received this message because you are subscribed to the Google Groups
"Prototype: Core" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to [EMAIL PROTECTED]
For more options, visit this group at
http://groups.google.com/group/prototype-core?hl=en
-~----------~----~----~----~------~----~------~--~---