Subj : Re: Equivalent of JS_InitClass for global object? To : netscape.public.mozilla.jseng From : Brendan Eich Date : Mon Aug 25 2003 02:00 pm Brendan Eich wrote: > John J Lee wrote: > >> I'll take your word for that, but I don't understand why (I *do* still >> have window objects in Python -- it's just that rather than bind one >> directly as the global object, I just have a function bind_window that >> fakes a JS global object by grabbing the individual attributes and >> methods >> from a window object and binding them to my simple JS global object). >> > > Windows are global objects in the DOM level 0, so a variable (var x = > 42, e.g.) or function declaration (function f() {return 42;} at > top-level) finds I meant to write "binds" here, not "finds" (although for the variable case, per ECMA-262, if a property named x already existed when the execution context for 'var x = 42' was entered, that pre-existing property would be used; it would not be blown away and replaced by a new property -- and so, if it were read-only, you'd get a runtime error trying to set it to 42). /be > a property of the global object, which can be fetched via window.x or > window.f, or if in another window accessible according to security > policy and frame/framset or window.open call prerequisites, > otherWindow.x or otherWindow.f. > > Plus, you can count on window object identity invariance: > otherWindow.myWindow = window; ; > assert(otherWindow.myWindow == window). > > Does your window object not being the global object magically satisfy > these constraints? > >> What's the best way to find out about this kind of thing? ATM, I don't >> know, for example, whether all these frames / windows have their own >> scopes / global objects / JSContexts -- your answer seems to hint at >> something like this. Am I stuck with either attempting to read the >> Mozilla source, or guessing by looking at piles of real-world JS code? >> > > Other browsers have managed to implement the DOM level 0, even though > the w3c never stepped up and standardized it. Perhaps the question of > specifying it enough for you to implement it without reading Mozilla > sources should be turned over to the w3c. Or to the > news://news.mozilla.org/netscape.public.mozilla.dom newsgroup, at least. > > /be > .