__parent__ property no longer works in firefox as expected

J

jgabios

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.
 
T

Thomas 'PointedEars' Lahn

jgabios said:
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
 
D

David Mark

  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.


See above.


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 = ...
  }





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.)
 
T

Thomas 'PointedEars' Lahn

kangax said:
Thomas said:
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*.

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
 
J

jgabios

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
 
J

Jeremy J Starcher

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.
 

Ask a Question

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

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,999
Messages
2,570,243
Members
46,835
Latest member
lila30

Latest Threads

Top