Subj : Re: Any reason for Math.sin.__parent__ == Math ? To : netscape.public.mozilla.jseng From : Igor Bukanov Date : Tue Mar 30 2004 11:29 am Brendan Eich wrote: > Igor Bukanov wrote: > >> Hi! >> >> In the current SM parent scope for functions of the standard host >> objects points to the object itself and not to the global scope so: >> >> js> Math.sin.__parent__ == Math >> true >> js> Math.sin.__parent__ >> [object Math] >> js> Math.sin.__parent__.__parent__ >> [object global] >> js> >> >> Any reason for that? It seems ECMA 262 is silent on this issue. > > > __parent__ is a generalization of [[Scope]], which ECMA-262 Edition 3 > specifies only for Function objects created per 13.2. The spec does not > cover the [[Scope]] property of native function objects. > > SpiderMonkey defines all static methods (Math.sin is analogous to > Date.parse in this respect; they are called static methods after Java's > class-member static methods) in the scope of their class constructor or > prototype. Math is not a constructor, it's a prototype singleton. > > Is this ancient self-consistent behavior of SpiderMonkey causing some > script use-case, or perhaps Rhino, some stress? Nothing significant but Rhino had a bug when scope was not initialized for static functions. The bug would probably not happen if all scopes would be initialized to global object as in Rhino case emulating SM behavior required a few additional lines of code. So I thought that was essential for some reasons... Regards, Igor .