Subj : Re: "named" vs. anonymous function To : netscape.public.mozilla.jseng From : Jens Thiele Date : Mon Dec 13 2004 04:10 pm Brendan Eich schrieb: > To clarify further, a named function object, per ECMA-262 Edition 3 > 11.2.5 and 13, the production: > > FunctionExpression : > function Identifier ( FormalParameterListopt ) { FunctionBody } > > A named function expression is scoped by an Object created to hold its > name only while it is active. That is its activation's scope parent, so > that cannot match the compiler-visible static scope parent (the global > object in your js shell example). Hence the clone. > > Named and anonymous function objects do have different scope chains, per > ECMA-262 Edition 3, but that does not map directly onto the __proto__ > difference you discovered. The latter is really an implementation > detail allowed by the spec. > > /be So this this is not really a matter of named vs. anonymous function but a matter of scope? Test: js> (function(){return function(){};})().__proto__===Function.prototype false js> (function(){return function(){};})().__proto__.__proto__===Function.prototype true though this example strictly wouldn't require a scope object? perhaps better? js> (function (){var i=10;return function(){return i;};})().__proto__===Function.prototype false js> (function (){var i=10;return function(){return i;};})().__proto__.__proto__===Function.prototype true looking at the source (jsinterp.c) the relevant parts seem to be: JSOP_ANONFUNOBJ, JSOP_NAMEDFUNOBJ and JSOP_CLOSURE (probably not JSOP_DEFFUN) in any way it is the call to js_CloneFunctionObject creating the clone / additional prototype I think I better stop now and get back to work again. Curiosity killed the cat ;-) Thanks Jens .