Obtaining a list of an obect's methods.

Discussion in 'Javascript' started by Daz, Dec 6, 2006.

  1. Daz

    Daz Guest

    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.
     
    Daz, Dec 6, 2006
    #1
    1. Advertising

  2. Daz

    VK Guest

    Daz wrote:
    > 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>
     
    VK, Dec 6, 2006
    #2
    1. Advertising

  3. Daz

    Daz Guest

    VK wrote:

    > Daz wrote:
    > > 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.
     
    Daz, Dec 6, 2006
    #3
  4. Daz

    Matt Kruse Guest

    Daz wrote:
    > 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.

    --
    Matt Kruse
    http://www.JavascriptToolbox.com
    http://www.AjaxToolbox.com
     
    Matt Kruse, Dec 6, 2006
    #4
  5. Daz

    RobG Guest

    Daz wrote:
    > 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 >

    --
    Rob
     
    RobG, Dec 6, 2006
    #5
  6. Daz

    Daz Guest

    Hi ROb, thanks for the reply.

    RobG wrote:

    > Daz wrote:
    > > 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
    > >

    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.

    RobG wrote:
    > However, simply getting an object's properties and then guessing how to
    > use them is not a sound way to program -

    Agreed!
    RobG wrote:
    > 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 wrote:
    > 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.
     
    Daz, Dec 10, 2006
    #6
  7. Daz

    VK Guest

    Daz wrote:
    > 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.
     
    VK, Dec 11, 2006
    #7
  8. Daz

    Daz Guest

    VK wrote:

    > Daz wrote:
    > > 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.
     
    Daz, Dec 11, 2006
    #8
    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. Joseph Cook

    Switching obect's type--sort of.

    Joseph Cook, Nov 21, 2003, in forum: C++
    Replies:
    7
    Views:
    435
    Howard
    Nov 21, 2003
  2. pelegk1

    dynamic obect access

    pelegk1, Jul 15, 2007, in forum: .NET
    Replies:
    0
    Views:
    300
    pelegk1
    Jul 15, 2007
  3. =?Utf-8?B?cGVsZWdrMQ==?=

    dynamic obect access

    =?Utf-8?B?cGVsZWdrMQ==?=, Jul 15, 2007, in forum: ASP .Net
    Replies:
    1
    Views:
    293
    Masudur
    Jul 15, 2007
  4. Replies:
    9
    Views:
    247
    Timothy Grant
    Aug 27, 2008
  5. srinivasan srinivas

    calling obect method

    srinivasan srinivas, Jul 30, 2009, in forum: Python
    Replies:
    1
    Views:
    285
Loading...

Share This Page