Subj : Re: "named" vs. anonymous function To : Jens Thiele From : Brendan Eich Date : Fri Dec 10 2004 02:20 pm Jens Thiele wrote: > Hi, > > just out of curiousity: > why do named functions have an additional prototype (in spidermonkey)? > example: > This is so that each function has the proper scope parent, yet we don't have to compile each time to get a new function for each dynamic scope. Each dynamic scope, when activated, gets a clone of the compiler-created function object, whose __proto__ is that compiler-created funobj. ECMA does not specify __proto__, so there's no way for a script to notice this difference. It could notice that function object identity (== or ===) differs, but that's allowed by Edition 3 (search for "joined function object"). /be > spidermonkey shell: > > js> x=function foo(){} > function foo() { > } > > js> y=function (){} > function () { > } > > js> x.__proto__===Function.prototype > false > js> x.__proto__.__proto__===Function.prototype > true > js> y.__proto__===Function.prototype > true > > a graph perhaps better visualizing it: > (13k) > > rhino does not do this: > > js> x=function foo(){} > function foo() { > } > > js> y=function (){} > function () { > } > > js> x.__proto__===Function.prototype > true > js> y.__proto__===Function.prototype > true > > > Jens .