Obtaining a list of an obect's methods.

D

Daz

Hi everyone.

I just wanted to know if there was any way to use script to display a
list of methods linked to a particular object? The object I have in
mind is getBrowser(), and I can't seem to find any documentation online
with regards to it's methods.

Also, as I am learning, it would be nice to be able to know what
methods are available for a particular object/function, without
necessarily having to spend a while looking up an object's method when
it's documented in a lot of different places, but only vaguely.

Many thanks.

Daz.
 
V

VK

Daz said:
Hi everyone.

I just wanted to know if there was any way to use script to display a
list of methods linked to a particular object? The object I have in
mind is getBrowser(), and I can't seem to find any documentation online
with regards to it's methods.

what object on what UA has getObject() method? I'm not aware of any.


<html>
<head>
<title>Object properties</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<div>
<script type="text/javascript">

// change window on any other object
// you want to study:
var myObject = window;

var prop = new Array;
for (var p in myObject) {
prop.push(p);
}
prop.sort();
for (var i=0; i<prop.length; ++i) {
document.writeln(prop + ' = ' + myObject[prop] + '<br>');
}
</script>
</div>
</body>
</html>
 
D

Daz

VK said:
Daz said:
Hi everyone.

I just wanted to know if there was any way to use script to display a
list of methods linked to a particular object? The object I have in
mind is getBrowser(), and I can't seem to find any documentation online
with regards to it's methods.

what object on what UA has getObject() method? I'm not aware of any.


<html>
<head>
<title>Object properties</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body>
<div>
<script type="text/javascript">

// change window on any other object
// you want to study:
var myObject = window;

var prop = new Array;
for (var p in myObject) {
prop.push(p);
}
prop.sort();
for (var i=0; i<prop.length; ++i) {
document.writeln(prop + ' = ' + myObject[prop] + '<br>');
}
</script>
</div>
</body>
</html>


Thanks for that VK. That will come in very useful, although
unfortunately it doesn't work with getBrowser(). The problem is most
likely that I am not using getBrowser in the correct context, as I
don't know what it's a method of. I have thried Browser, BrowserObj,
window, and document, none of which seem to work.

I am trying to create an extension for Firefox and perhaps I am getting
confused between the standard JavaScript and the functions built-in to
Firefox.
 
M

Matt Kruse

Daz said:
The object I have in mind is getBrowser()

That's not an object, it's a function call.
And not a standard browser function, either.
Which means you're using some library, and we can't help unless we know what
library you're using.

Further, the getBrowser() function name leads me to believe that you're
doing some browser sniffing, which is not a good sign...
and I can't seem to find any documentation
online with regards to it's methods.

Well, where did you get it from? :)
Also, as I am learning, it would be nice to be able to know what
methods are available for a particular object/function, without
necessarily having to spend a while looking up an object's method when
it's documented in a lot of different places, but only vaguely.

Links at http://www.javascripttoolbox.com/resources/ should be extremely
helpful.
 
R

RobG

Daz said:
Hi everyone.

I just wanted to know if there was any way to use script to display a
list of methods linked to a particular object? The object I have in
mind is getBrowser(), and I can't seem to find any documentation online
with regards to it's methods.

Google is your friend, is this what you are looking for?

<URL: http://www.xj3d.org/javadoc/vrml/eai/BrowserFactory.html >

Note that is a Java function, which is very different to javascript.
This thread may be useful too:

<URL:
http://www.web3d.org/x3d/publiclists/x3dpublic_list_archives/0601/msg00004.html
Also, as I am learning, it would be nice to be able to know what
methods are available for a particular object/function, without
necessarily having to spend a while looking up an object's method when
it's documented in a lot of different places, but only vaguely.

In javascript, you can use for..in to get the enumerable properties of
an object. Whenever you call a function on its own it is likely that
you are calling it as a method of the window object, but you need to
understand the scope chain when the function is called to know that.

You can also use hasOwnProperty to determine if a method is a property
of the object itself or is inherited from its prototype chain.

However, simply getting an object's properties and then guessing how to
use them is not a sound way to program - how will you know what
arguments to pass, or how they are used? Use the FAQ to get a list of
on-line references, including those for JavaScript, JScript and various
DOM standards and implementations.

<URL: http://www.jibbering.com/faq/#FAQ3 >
 
D

Daz

Hi ROb, thanks for the reply.
Google is your friend, is this what you are looking for?

<URL: http://www.xj3d.org/javadoc/vrml/eai/BrowserFactory.html >

Note that is a Java function, which is very different to javascript.
This thread may be useful too:

<URL:
http://www.web3d.org/x3d/publiclists/x3dpublic_list_archives/0601/msg00004.html
Unfortunately, neither of those URLs were useful with regards to
finding the methods of the getBrowser object. I think it's just one of
those things that's not very well documented.
However, simply getting an object's properties and then guessing how to
use them is not a sound way to program -
Agreed!
RobG said:
how will you know what
arguments to pass, or how they are used?
I don't. I will then know what methods are available, and then
hopefully be able to go and look them up with more success. Also, it's
a way of learning, and happens to be one of my preferred methods.
Rather than struggling to find a a method that I don't know exists, I
prefer to be able to read about various methods in my own time, and
often, when I need it most, I have at least a vague idea of what I
might need to use, so it's then just a case of looking up the syntax.
Most method names are quite descripitive, although not all of them.

The way I see it, is it's a bit like trying to memorize the chapter
names in a book, as opposed to trying to remember the chapters names
and the text from each chapter. I hope this makes sense to you.
RobG said:
Use the FAQ to get a list of
on-line references, including those for JavaScript, JScript and various
DOM standards and implementations.

<URL: http://www.jibbering.com/faq/#FAQ3 >
Now that's going to come in handy, although again, some what I am doing
is only really borderline JavaScript. It's JavaScript based, but not
necessarily part of the JavaScript core. I believe that getBrowser is a
JavaScript function that is native to Mozilla/Firefox, but I am not
100% on that.

Thanks again for your help.

Daz.
 
V

VK

Daz said:
I believe that getBrowser is a
JavaScript function that is native to Mozilla/Firefox, but I am not
100% on that.

OK, this hint broke the circle, though the question was *really*
cryptic.
It would be much more helpful to read something like: "at URL ... I
have found a mention of getBrowser used for ... What is it and where is
it?".

////////////

There is not native getBrowser object in JavaScript client-side
scripting. Thus any researches of it are even more futile than the
search of the Holly Grail :)

Nevertheless:

Firefox 2.0 makes the first big step in implementing client-side
session data storage which IE users are enjoying with since 5.0
<http://msdn.microsoft.com/workshop/author/behaviors/reference/behaviors/userdata.asp>

In the particular Firefox 2.0 implements XPCOM session store API over
nsISessionStore interface. One of methods available over this interface
is getBrowserState() method
<http://developer.mozilla.org/en/docs/nsISessionStore#getBrowserState.28.29>

At <http://developer.mozilla.org/en/docs/Session_restore_API> it is
referred by mistake as getBrowser() method (the author must be got
confused with GetBrowser from BrowserHawk).

Overall the code snippets from
<http://developer.mozilla.org/en/docs/Session_restore_API> are getting
my prize by the amount of errors per line of code. That is atop of the
fact that the quality of samples for XPCOM / netscape.security matters
is awful both for MDC and XULPlanet. It is so thoroughly insistently
perpetually awful that I can explain it only by:

1) all writing goes under intoxication.
2) no one (including Gecko developers themselves) has a clue on the
matters.
3) until the relevant technologies are tested and interfaces are frozen
- until then an "allowance encryption" is used. Thus if someone knows
the matter she will be able to correct the code in the needed way so
use it for testing. Anyone else will fail to use the code so she will
give up for now.

Needless to say that I believe and hope that the most favorable to
Mozilla option (the third one) is the real true.

I myself once had to work extensively with Netscape Capabilities APIs
for JVM and the involved matters. This way now I'm in the position of
Cicero listening some drunk Roman legionnaire from a far province :) -
with some efforts made I can understand what a hey is he talking about
and write down his speech with the proper words and in the proper
grammatical forms.

Sorry for blah-blah, anyway...

So there is nsISessionStore interface, and this interface implements
getBrowserState method. There is no "getBrowser" method in it: that is
a phantasm of a MDC participant.

nsISessionStore interface is accessible over XPCOM interface for
Firefox 2.0 or higher. XPCOM interface is not accessible until the
needed privilege is granted to the browser. This way the restored code
is:

!!! Important: Google News corrupts strings on display if they contain
@ (at-sign). Because XPCOM call contains at-sign, this code will be
corrupted and not working if copied from your browser window. After
copy and past first locate the string
Components.classes['
and remove dotes (ellipsis) right after the single quote.

<html>
<head>
<title>getBrowserState</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body onload="
/* Firefox 2.0 or higher.
* Security restrictions are applied
* (cannot be run within the default sandbox).
*/
netscape.security.PrivilegeManager.
enablePrivilege('UniversalXPConnect');
var s = Components.classes['@mozilla.org/browser/sessionstore;1'].
getService(Components.interfaces.nsISessionStore);
s.init(self);
window.alert(s.getBrowserState());
">
</body>
</html>


P.S. No, I will not jump on correcting relevant sections on XULPlanet
or MDC - though anyone is welcome to replace the current nonsense at
<http://developer.mozilla.org/en/docs/Session_restore_API> with the
posted sample.
First of all, IMHO it's like emptying an ocean with a bucket. Secondly
and most importantly I do not agree with the MDC concept of "OK, guys,
we've programmed some cool stuff, you tell us what is it doing". Excuse
me: it is not an end-users' task to document "black boxes" over
try-fail-success cycles. Each programmer has to place an fn initial
document clearly stating what the hay is done, how in the name is it
done, what the fricking arguments are required, what the hell methods
are supported. That can be a plain text file or a scan image copy of a
sticker from his desktop: *anything* to start with. Then we can test
it, report bugs, "put the flash" of nicer wording and samples.
That seems not only my opinion, but a background feeling of many other
people: at least from one year to another MDC fails to be as helpful as
expected for advanced Gecko features.
 
D

Daz

VK said:
Daz said:
I believe that getBrowser is a
JavaScript function that is native to Mozilla/Firefox, but I am not
100% on that.

OK, this hint broke the circle, though the question was *really*
cryptic.
It would be much more helpful to read something like: "at URL ... I
have found a mention of getBrowser used for ... What is it and where is
it?".

////////////

There is not native getBrowser object in JavaScript client-side
scripting. Thus any researches of it are even more futile than the
search of the Holly Grail :)

Nevertheless:

Firefox 2.0 makes the first big step in implementing client-side
session data storage which IE users are enjoying with since 5.0
<http://msdn.microsoft.com/workshop/author/behaviors/reference/behaviors/userdata.asp>

In the particular Firefox 2.0 implements XPCOM session store API over
nsISessionStore interface. One of methods available over this interface
is getBrowserState() method
<http://developer.mozilla.org/en/docs/nsISessionStore#getBrowserState.28.29>

At <http://developer.mozilla.org/en/docs/Session_restore_API> it is
referred by mistake as getBrowser() method (the author must be got
confused with GetBrowser from BrowserHawk).

Overall the code snippets from
<http://developer.mozilla.org/en/docs/Session_restore_API> are getting
my prize by the amount of errors per line of code. That is atop of the
fact that the quality of samples for XPCOM / netscape.security matters
is awful both for MDC and XULPlanet. It is so thoroughly insistently
perpetually awful that I can explain it only by:

1) all writing goes under intoxication.
2) no one (including Gecko developers themselves) has a clue on the
matters.
3) until the relevant technologies are tested and interfaces are frozen
- until then an "allowance encryption" is used. Thus if someone knows
the matter she will be able to correct the code in the needed way so
use it for testing. Anyone else will fail to use the code so she will
give up for now.

Needless to say that I believe and hope that the most favorable to
Mozilla option (the third one) is the real true.

I myself once had to work extensively with Netscape Capabilities APIs
for JVM and the involved matters. This way now I'm in the position of
Cicero listening some drunk Roman legionnaire from a far province :) -
with some efforts made I can understand what a hey is he talking about
and write down his speech with the proper words and in the proper
grammatical forms.

Sorry for blah-blah, anyway...

So there is nsISessionStore interface, and this interface implements
getBrowserState method. There is no "getBrowser" method in it: that is
a phantasm of a MDC participant.

nsISessionStore interface is accessible over XPCOM interface for
Firefox 2.0 or higher. XPCOM interface is not accessible until the
needed privilege is granted to the browser. This way the restored code
is:

!!! Important: Google News corrupts strings on display if they contain
@ (at-sign). Because XPCOM call contains at-sign, this code will be
corrupted and not working if copied from your browser window. After
copy and past first locate the string
Components.classes['
and remove dotes (ellipsis) right after the single quote.

<html>
<head>
<title>getBrowserState</title>
<meta http-equiv="Content-Type"
content="text/html; charset=iso-8859-1">
</head>
<body onload="
/* Firefox 2.0 or higher.
* Security restrictions are applied
* (cannot be run within the default sandbox).
*/
netscape.security.PrivilegeManager.
enablePrivilege('UniversalXPConnect');
var s = Components.classes['@mozilla.org/browser/sessionstore;1'].
getService(Components.interfaces.nsISessionStore);
s.init(self);
window.alert(s.getBrowserState());
">
</body>
</html>


P.S. No, I will not jump on correcting relevant sections on XULPlanet
or MDC - though anyone is welcome to replace the current nonsense at
<http://developer.mozilla.org/en/docs/Session_restore_API> with the
posted sample.
First of all, IMHO it's like emptying an ocean with a bucket. Secondly
and most importantly I do not agree with the MDC concept of "OK, guys,
we've programmed some cool stuff, you tell us what is it doing". Excuse
me: it is not an end-users' task to document "black boxes" over
try-fail-success cycles. Each programmer has to place an fn initial
document clearly stating what the hay is done, how in the name is it
done, what the fricking arguments are required, what the hell methods
are supported. That can be a plain text file or a scan image copy of a
sticker from his desktop: *anything* to start with. Then we can test
it, report bugs, "put the flash" of nicer wording and samples.
That seems not only my opinion, but a background feeling of many other
people: at least from one year to another MDC fails to be as helpful as
expected for advanced Gecko features.

Many thanks for your input. You make some very interesting points, most
of which I happen to agree with. No worries about the 'blah-blah'. I
enjoy reading what others have to say, especially when I have the
opportunity to learn from it, as well as increasing my understanding of
the subject and possibly changing my opinions which could have been
made without the correct information.

Thanks again.

Daz.
 

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

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,021
Latest member
AkilahJaim

Latest Threads

Top