__parent__ property no longer works in firefox as expected

Discussion in 'Javascript' started by jgabios, Apr 21, 2009.

  1. jgabios

    jgabios Guest

    i have firefox 3.0.8.
    and i have the following code:

    (function(){
    function N(){
    alert('N');
    }
    function Y(){
    alert('Y');
    }
    window.goog=Y;
    })();

    if i do goog.__parent__ it gives me null;

    the code:
    function A(){
    alert('A');
    }

    window.A.__parent__ gives me reference to the window.

    is there another way to get a reference to the anonymous function
    first listed as goog(it is Y).__parent__ goes to null?

    thank you in advance.
    --
    jgabios
    http://bash.editia.info
    jgabios, Apr 21, 2009
    #1
    1. Advertising

  2. jgabios wrote:
    > i have firefox 3.0.8.
    > and i have the following code:
    >
    > (function(){
    > function N(){
    > alert('N');


    window.alert(...);

    `alert' is no longer a JavaScript feature since version 1.4, and it has
    never been a language feature in other ECMAScript implementations.

    > }
    > function Y(){
    > alert('Y');


    See above.

    > }
    > window.goog=Y;


    Don't augment host objects.

    One refers to the ECMAScript Global Object explicitly by `this' if the
    caller is the Global Object or null, or e.g. by `_global' in local context
    with `_global = this' in global context:

    (
    function ...(...) {
    this.goog = ...
    }
    )()

    or

    var _global = this;

    function ...(...)
    {
    _global.goog = ...
    }

    Usually you would declare the identifier a variable and make use of the
    scope chain, though, or you would use the function as the object that it is.

    var goog;

    function foo(...)
    {
    goog = ...

    /* or */

    foo.goog = ...
    /* or */
    arguments.callee.goog = ...
    }

    > })();
    >
    > if i do goog.__parent__ it gives me null;
    >
    > the code:
    > function A(){
    > alert('A');
    > }
    >
    > window.A.__parent__ gives me reference to the window.


    Consider that a happy coincidence. (Netscape/Mozilla.org) JavaScript is but
    one of many ECMAScript implementations (see e.g. Microsoft JScript), and
    `window' refers to a host object. (I have neither ever heard of that
    property before nor did I need to make use of such, and I need two hands to
    count the years I'm doing ECMAScript implementations now. But thanks for
    mentioning, it will be added to the ECMAScript Support Matrix.)

    > is there another way to get a reference to the anonymous function
    > first listed as goog(it is Y).__parent__ goes to null?


    IIUC,

    (
    function() {
    function N(){
    window.alert('N');
    }

    function Y() {
    window.alert('Y');
    }

    return arguments.callee;
    }
    )()

    However, one wonders what do you think you need this for, and why.


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 21, 2009
    #2
    1. Advertising

  3. jgabios

    David Mark Guest

    On Apr 21, 9:35 am, Thomas 'PointedEars' Lahn <>
    wrote:
    > jgabios wrote:
    > > i have firefox 3.0.8.
    > > and i have the following code:

    >
    > > (function(){
    > > function N(){
    > > alert('N');

    >
    >   window.alert(...);
    >
    > `alert' is no longer a JavaScript feature since version 1.4, and it has
    > never been a language feature in other ECMAScript implementations.
    >
    > > }
    > > function Y(){
    > > alert('Y');

    >
    > See above.
    >
    > > }
    > > window.goog=Y;

    >
    > Don't augment host objects.
    >
    > One refers to the ECMAScript Global Object explicitly by `this' if the
    > caller is the Global Object or null, or e.g. by `_global' in local context
    > with `_global = this' in global context:
    >
    >   (
    >     function ...(...) {
    >       this.goog = ...
    >     }
    >   )()
    >
    > or
    >
    >   var _global = this;
    >
    >   function ...(...)
    >   {
    >     _global.goog = ...
    >   }
    >
    > Usually you would declare the identifier a variable and make use of the
    > scope chain, though, or you would use the function as the object that it is.
    >
    >   var goog;
    >
    >   function foo(...)
    >   {
    >     goog = ...
    >
    >     /* or */
    >
    >     foo.goog = ...
    >     /* or */
    >     arguments.callee.goog = ...
    >   }
    >
    > > })();

    >
    > > if i do goog.__parent__ it gives me null;

    >
    > > the code:
    > > function A(){
    > > alert('A');
    > > }

    >
    > > window.A.__parent__ gives me reference to the window.

    >
    > Consider that a happy coincidence.  (Netscape/Mozilla.org) JavaScript is but
    > one of many ECMAScript implementations (see e.g. Microsoft JScript), and
    > `window' refers to a host object.  (I have neither ever heard of that
    > property before nor did I need to make use of such, and I need two hands to
    > count the years I'm doing ECMAScript implementations now.  But thanks for
    > mentioning, it will be added to the ECMAScript Support Matrix.)


    [snip]

    I hadn't either, until Richard mentioned it was in IceBrowser. Can be
    used to get the window from the document when other properties are
    unavailable (as in IceBrowser.)
    David Mark, Apr 21, 2009
    #3
  4. kangax wrote:
    > Thomas 'PointedEars' Lahn wrote:
    >> jgabios wrote:

    > [...]
    >>> window.goog=Y;

    >> Don't augment host objects.

    >
    > Where's the host object augmentation here? I always thought that a
    > global `window` property references a built-in native Global object,
    > not a host object.


    You always thought wrong. Nothing specifies that to be (remember that
    examples in Specifications are not normative), and if the object that this
    host-defined property refers to happens to mirror properties of the Global
    Object then that's merely a happy coincidence.

    > Could you elaborate, please?


    Not *again*.

    <https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference#Global_Objects>

    >>> window.A.__parent__ gives me reference to the window.

    >> Consider that a happy coincidence. (Netscape/Mozilla.org) JavaScript is but
    >> one of many ECMAScript implementations (see e.g. Microsoft JScript), and
    >> `window' refers to a host object. (I have neither ever heard of that
    >> property before nor did I need to make use of such, and I need two hands to
    >> count the years I'm doing ECMAScript implementations now. But thanks for
    >> mentioning, it will be added to the ECMAScript Support Matrix.)

    >
    > There are other Mozilla non-standard ones, such as __count__,
    > __defineGetter__ and __defineSetter__ which don't seem to be in the
    > matrix
    > <https://developer.mozilla.org/En/Core_JavaScript_1.5_Reference/Global_Objects/Object>


    I have the latter two locally already, along with __iterator__ and
    __proto__. Thanks for the hint, though.


    PointedEars
    Thomas 'PointedEars' Lahn, Apr 22, 2009
    #4
  5. jgabios

    jgabios Guest


    >
    > However, one wonders what do you think you need this for, and why.
    >
    > PointedEars


    i am trying to make a greasemonkey script, on youtube.com, and there
    is a function N inside an anonymous function.
    alongside with function N, there are other functions inside that
    anonymous function that are referenced to the outside code with lines
    like this: window.goog.disabled=Y; and so on.
    so i can access the Y function inside the anonymous function.
    now i wanted to get a reference to the N function by going Y -> parent
    -> N as functions are objects.
    so, that's my case.
    maybe my approach is bad, and cannot be done [i need it to work on
    firefox, not interested in other browsers] , do you know any other way
    to get to N function?
    i also tried to look for a reference of the anonymous function [i know
    it is not assigned to a var] but i thought a random property of the
    window global object would have been assigned to it. anyway i get
    carried away. i stop.

    jgabios
    jgabios, Apr 22, 2009
    #5
  6. On Tue, 21 Apr 2009 23:40:54 -0700, jgabios wrote:


    >> However, one wonders what do you think you need this for, and why.
    >>
    >> PointedEars

    >
    > i am trying to make a greasemonkey script, on youtube.com, and there is
    > a function N inside an anonymous function. alongside with function N,
    > there are other functions inside that anonymous function that are
    > referenced to the outside code with lines like this:
    > window.goog.disabled=Y; and so on. so i can access the Y function inside
    > the anonymous function. now i wanted to get a reference to the N
    > function by going Y -> parent -> N as functions are objects.
    > so, that's my case.



    [ Edited to simplify language for OP ]

    Assuming you are referring to the 'true' GreaseMonkey and not one of the
    other user-script extensions for IE, Chrome, or Konq:

    GreaseMonkey has its own private 'window' variable that is separate from
    the window the document sees. The 'real' window, if I can call it that,
    is referred to as 'unsafeWindow.'


    I often include a line line:

    var mainWindow = (typeof unsafeWindow !== 'undefined') ? unsafeWindow :
    window;

    GreaseMonkey scripts are their own world. Javascript, yes, but only a
    small part of the DOM is available so they can provide a 'wall' to keep
    the document's scripts from looking into into GreaseMonkey private data.
    Jeremy J Starcher, Apr 22, 2009
    #6
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Cory Nelson
    Replies:
    2
    Views:
    394
    Cory Nelson
    Apr 15, 2004
  2. =?Utf-8?B?QnJ5YW4gWk0=?=
    Replies:
    1
    Views:
    1,143
    =?Utf-8?B?QnJ5YW4gWk0=?=
    May 26, 2005
  3. bb
    Replies:
    2
    Views:
    373
  4. Colin Steadman
    Replies:
    2
    Views:
    267
    Colin Steadman
    Oct 14, 2004
  5. mephraim

    cssRules No Longer Works in FireFox 1.5

    mephraim, Jan 22, 2006, in forum: Javascript
    Replies:
    19
    Views:
    223
    Thomas 'PointedEars' Lahn
    Feb 1, 2006
Loading...

Share This Page