Accessing an object name

Discussion in 'Javascript' started by TonyV, Nov 26, 2007.

  1. TonyV

    TonyV Guest

    Hey all, for debugging purposes, I'd like to be able to access an
    object's instance name from within the object class. For example, I'd
    like to be able to do something like this:

    ------------------------------------------------------------
    function FooClass() {
    // definition of FooClass members
    }

    FooClass.prototype.Debug = function() {
    // Need help here to display correct information
    alert("My name is ...?");
    }

    var monkeybutter = new FooClass();
    monkeybutter.Debug(); // I'd like this to display "My name is
    monkeybutter"
    ------------------------------------------------------------

    Is this possible, and if so, how?
     
    TonyV, Nov 26, 2007
    #1
    1. Advertising

  2. TonyV

    Kailash Nadh Guest

    On Nov 26, 5:57 pm, TonyV <> wrote:
    > Hey all, for debugging purposes, I'd like to be able to access an
    > object's instance name from within the object class. For example, I'd
    > like to be able to do something like this:
    >
    > ------------------------------------------------------------
    > function FooClass() {
    > // definition of FooClass members
    >
    > }
    >
    > FooClass.prototype.Debug = function() {
    > // Need help here to display correct information
    > alert("My name is ...?");
    >
    > }
    >
    > var monkeybutter = new FooClass();
    > monkeybutter.Debug(); // I'd like this to display "My name is
    > monkeybutter"
    > ------------------------------------------------------------
    >
    > Is this possible, and if so, how?


    arguments.callee construct might be of help.
    http://www.devguru.com/Technologies/ecmascript/QuickRef/arguments.html

    Kailash Nadh | http://kailashnadh.name
     
    Kailash Nadh, Nov 26, 2007
    #2
    1. Advertising

  3. TonyV

    VK Guest

    On Nov 26, 8:57 pm, TonyV <> wrote:
    > Hey all, for debugging purposes, I'd like to be able to access an
    > object's instance name from within the object class. For example, I'd
    > like to be able to do something like this:
    >
    > ------------------------------------------------------------
    > function FooClass() {
    > // definition of FooClass members
    >
    > }
    >
    > FooClass.prototype.Debug = function() {
    > // Need help here to display correct information
    > alert("My name is ...?");
    >
    > }
    >
    > var monkeybutter = new FooClass();
    > monkeybutter.Debug(); // I'd like this to display "My name is
    > monkeybutter"


    var monkeybutter = new FooClass('monkeybutter');
    function FooClass() {
    this._name = arguments[0] || 'anonymous';
    // definition of FooClass members
    }

    FooClass.prototype.Debug = function() {
    alert("My name is " + this._name);
    }
     
    VK, Nov 26, 2007
    #3
  4. On Mon, 26 Nov 2007 at 09:57:29, in comp.lang.javascript, TonyV wrote:
    >Hey all, for debugging purposes, I'd like to be able to access an
    >object's instance name from within the object class. For example, I'd
    >like to be able to do something like this:
    >
    >------------------------------------------------------------
    >function FooClass() {
    > // definition of FooClass members
    >}
    >
    >FooClass.prototype.Debug = function() {
    > // Need help here to display correct information
    > alert("My name is ...?");
    >}
    >
    >var monkeybutter = new FooClass();


    var a = monkeybutter;
    var b = a;
    var c = b;

    >monkeybutter.Debug(); // I'd like this to display "My name is
    >monkeybutter"


    Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    (Note : all those variables point to the same object).

    What if you also did

    d.e.f["fred"]().g.h = c;

    Now what do you want to display?

    >------------------------------------------------------------
    >
    >Is this possible, and if so, how?


    After a bit of thought you now realise that that was the wrong question.
    As usual, you need to start with the right first question :

    "What do I *really* want to do?"

    From your first paragraph it looks as though you want each FooClass
    object to hold its own object identifier. Then VK's solution is your
    answer, though call it 'oid', not 'name', as 'name' is too likely to be
    needed for real names. Now the oid can be something convenient or
    significant, not restricted to the name of a global variable.

    John
    --
    John Harris
     
    John G Harris, Nov 27, 2007
    #4
  5. TonyV

    TonyV Guest

    On Nov 27, 3:50 pm, John G Harris <> wrote:
    > var a = monkeybutter;
    > var b = a;
    > var c = b;
    >
    > >monkeybutter.Debug(); // I'd like this to display "My name is
    > >monkeybutter"

    >
    > Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    > (Note : all those variables point to the same object).


    Easy: "monkeybutter."

    > After a bit of thought you now realise that that was the wrong question.
    > As usual, you need to start with the right first question :
    >
    > "What do I *really* want to do?"


    What I want to do is to have a debugging function in my class that
    will tell me which instance of said class the particular debugging
    information that follows applies to.
     
    TonyV, Nov 28, 2007
    #5
  6. On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javascript, TonyV wrote:
    >On Nov 27, 3:50 pm, John G Harris <> wrote:
    >> var a = monkeybutter;
    >> var b = a;
    >> var c = b;
    >>
    >> >monkeybutter.Debug(); // I'd like this to display "My name is
    >> >monkeybutter"

    >>
    >> Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    >> (Note : all those variables point to the same object).

    >
    >Easy: "monkeybutter."
    >
    >> After a bit of thought you now realise that that was the wrong question.
    >> As usual, you need to start with the right first question :
    >>
    >> "What do I *really* want to do?"

    >
    >What I want to do is to have a debugging function in my class that
    >will tell me which instance of said class the particular debugging
    >information that follows applies to.


    I'm afraid you're confusing us.

    Your first sentence says you want to know which variable you used to
    access an object.

    Your second sentence says you want to know which object you accessed.

    Which do you really want?

    John
    --
    John Harris
     
    John G Harris, Nov 29, 2007
    #6
  7. John G Harris wrote:
    > On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javascript, TonyV wrote:
    >> On Nov 27, 3:50 pm, John G Harris <> wrote:
    >>> var a = monkeybutter;
    >>> var b = a;
    >>> var c = b;
    >>>
    >>>> monkeybutter.Debug(); // I'd like this to display "My name is
    >>>> monkeybutter"
    >>> Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    >>> (Note : all those variables point to the same object).

    >> Easy: "monkeybutter."
    >>
    >>> After a bit of thought you now realise that that was the wrong question.
    >>> As usual, you need to start with the right first question :
    >>>
    >>> "What do I *really* want to do?"

    >> What I want to do is to have a debugging function in my class that
    >> will tell me which instance of said class the particular debugging
    >> information that follows applies to.

    >
    > I'm afraid you're confusing us.
    >
    > Your first sentence says you want to know which variable you used to
    > access an object.
    >
    > Your second sentence says you want to know which object you accessed.
    >
    > Which do you really want?


    It's easy enough to understand once you accept that he's asking for
    something grossly impossible; he wants an object to magically remember
    the name of the first variable it was ever assigned to.
    --
    John W. Kennedy
    "Compact is becoming contract,
    Man only earns and pays."
    -- Charles Williams. "Bors to Elayne: On the King's Coins"
     
    John W. Kennedy, Nov 30, 2007
    #7
  8. TonyV

    TonyV Guest

    On Nov 29, 8:58 pm, "John W. Kennedy" <> wrote:
    > It's easy enough to understand once you accept that he's asking for
    > something grossly impossible; he wants an object to magically remember
    > the name of the first variable it was ever assigned to.
    > --
    > John W. Kennedy


    There's nothing magical about it, and in spite of the condescending
    tone of that reply, it's not rocket science what I'm asking. I want
    to know if there's a way for an object instance to have access to
    information about itself, such as its name, if it has one.

    If it can't, then just say so. If it can, then I'd appreciate knowing
    how.

    > var a = monkeybutter;
    > var b = a;
    > var c = b;
    >
    > >monkeybutter.Debug(); // I'd like this to display "My name is
    > >monkeybutter"

    >
    > Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    > (Note : all those variables point to the same object).


    In a case like this, as I said, I'd love to have "monkeybutter," but
    I'd even be pleased for something like an array containing the values
    "monkeybutter," "a," "b," and "c" if multiple references to the same
    object instance exists.

    I never said I wanted to know which object was being accessed. I've
    been consistent in what I need the whole time: I need to know which
    object *instance* is being accessed to report for debugging purposes.
    If there's some kind of problem with an object instance, I'd like for
    the instance to be able to report, "Hey, this specific thing has
    something wrong with it. (As opposed to all the other things of the
    same type that you've declared.)" I guess I'm confused as to why
    there's so much confusion, the question seems pretty straight-forward,
    even if the answer is not.
     
    TonyV, Nov 30, 2007
    #8
  9. TonyV wrote:
    > On Nov 29, 8:58 pm, "John W. Kennedy" <> wrote:
    >> It's easy enough to understand once you accept that he's asking for
    >> something grossly impossible; he wants an object to magically remember
    >> the name of the first variable it was ever assigned to.
    >> --
    >> John W. Kennedy

    >
    > There's nothing magical about it, and in spite of the condescending
    > tone of that reply, it's not rocket science what I'm asking.


    Yes, there is; and yes, you are. The variable stores but an object
    reference, one of maybe many, which may have been created in a number
    of different ways.


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Nov 30, 2007
    #9
  10. TonyV

    VK Guest

    On Nov 30, 10:02 pm, TonyV <> wrote:
    > I never said I wanted to know which object was being accessed. I've
    > been consistent in what I need the whole time: I need to know which
    > object *instance* is being accessed to report for debugging purposes.


    You cannot do it - not in JavaScript nor in other languages AFAIK but
    my knowledge is limited.

    > If there's some kind of problem with an object instance, I'd like for
    > the instance to be able to report, "Hey, this specific thing has
    > something wrong with it.


    For that you have to custom mark each new instance as suggested in my
    first post so to report it later.

    No other way around. I hope it answers your question.
     
    VK, Nov 30, 2007
    #10
  11. On Thu, 29 Nov 2007 at 20:58:21, in comp.lang.javascript, John W.
    Kennedy wrote:
    >John G Harris wrote:
    >> On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javascript, TonyV wrote:
    >>> On Nov 27, 3:50 pm, John G Harris <> wrote:
    >>>> var a = monkeybutter;
    >>>> var b = a;
    >>>> var c = b;
    >>>>
    >>>>> monkeybutter.Debug(); // I'd like this to display "My name is
    >>>>> monkeybutter"
    >>>> Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    >>>> (Note : all those variables point to the same object).
    >>> Easy: "monkeybutter."
    >>>
    >>>> After a bit of thought you now realise that that was the wrong question.
    >>>> As usual, you need to start with the right first question :
    >>>>
    >>>> "What do I *really* want to do?"
    >>> What I want to do is to have a debugging function in my class that
    >>> will tell me which instance of said class the particular debugging
    >>> information that follows applies to.

    >> I'm afraid you're confusing us.
    >> Your first sentence says you want to know which variable you used to
    >> access an object.
    >> Your second sentence says you want to know which object you
    >>accessed.
    >> Which do you really want?

    >
    >It's easy enough to understand once you accept that he's asking for
    >something grossly impossible; he wants an object to magically remember
    >the name of the first variable it was ever assigned to.


    You're guessing. So am I. The trouble is that he knows what answer he's
    expecting but doesn't know, or can't describe, what question it's
    answering. Until we know the question we don't know which of six
    different solutions to suggest.

    John
    --
    John Harris
     
    John G Harris, Nov 30, 2007
    #11
  12. John G Harris wrote:
    > On Thu, 29 Nov 2007 at 20:58:21, in comp.lang.javascript, John W.
    > Kennedy wrote:
    >> John G Harris wrote:
    >>> On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javascript, TonyV wrote:
    >>>> On Nov 27, 3:50 pm, John G Harris <> wrote:
    >>>>> var a = monkeybutter;
    >>>>> var b = a;
    >>>>> var c = b;
    >>>>>
    >>>>>> monkeybutter.Debug(); // I'd like this to display "My name is
    >>>>>> monkeybutter"
    >>>>> Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    >>>>> (Note : all those variables point to the same object).
    >>>> Easy: "monkeybutter."
    >>>>
    >>>>> After a bit of thought you now realise that that was the wrong question.
    >>>>> As usual, you need to start with the right first question :
    >>>>>
    >>>>> "What do I *really* want to do?"
    >>>> What I want to do is to have a debugging function in my class that
    >>>> will tell me which instance of said class the particular debugging
    >>>> information that follows applies to.
    >>> I'm afraid you're confusing us.
    >>> Your first sentence says you want to know which variable you used to
    >>> access an object.
    >>> Your second sentence says you want to know which object you
    >>> accessed.
    >>> Which do you really want?

    >> It's easy enough to understand once you accept that he's asking for
    >> something grossly impossible; he wants an object to magically remember
    >> the name of the first variable it was ever assigned to.

    >
    > You're guessing. So am I. The trouble is that he knows what answer he's
    > expecting but doesn't know, or can't describe, what question it's
    > answering. Until we know the question we don't know which of six
    > different solutions to suggest.


    No, actually, I'm really not guessing. He is saying very plainly and
    unambiguously what it is that he wants; we're just having trouble
    understanding it because anyone with the slightest knowledge of
    programming -- in any language -- knows that what he's asking for is
    complete nonsense, and so our instincts make us want to believe that
    he's asking for something else, something sensible, instead. Humans are
    patter-matchers. But if you read his original message, it's very clear
    that he has gotten the notion into his head that the statement

    variablename = new objecttype;

    somehow forges a permanent and bilateral tie between the newly created
    object and the assigned-to variable -- that the new object is somehow
    "really" {variablename}, irrespective of whatever other variables it may
    subsequently be assigned to. I did not use the word "magic" arbitrarily
    here; this is essentially an analog of the magical Law of Contagion:
    "Objects once in contact continue to interact at a distance."

    --
    John W. Kennedy
    "Never try to take over the international economy based on a radical
    feminist agenda if you're not sure your leader isn't a transvestite."
    -- David Misch: "She-Spies", "While You Were Out"
     
    John W. Kennedy, Dec 1, 2007
    #12
  13. TonyV

    VK Guest

    On Dec 1, 8:09 am, "John W. Kennedy" <> wrote:
    > John G Harris wrote:
    > > On Thu, 29 Nov 2007 at 20:58:21, in comp.lang.javascript, John W.
    > > Kennedy wrote:
    > >> John G Harris wrote:
    > >>> On Wed, 28 Nov 2007 at 12:22:45, in comp.lang.javascript, TonyV wrote:
    > >>>> On Nov 27, 3:50 pm, John G Harris <> wrote:
    > >>>>> var a = monkeybutter;
    > >>>>> var b = a;
    > >>>>> var c = b;

    >
    > >>>>>> monkeybutter.Debug(); // I'd like this to display "My name is
    > >>>>>> monkeybutter"
    > >>>>> Now what do you want to display : "a", "b", "c", or "monkeybutter"?
    > >>>>> (Note : all those variables point to the same object).
    > >>>> Easy: "monkeybutter."

    >
    > >>>>> After a bit of thought you now realise that that was the wrong question.
    > >>>>> As usual, you need to start with the right first question :

    >
    > >>>>> "What do I *really* want to do?"
    > >>>> What I want to do is to have a debugging function in my class that
    > >>>> will tell me which instance of said class the particular debugging
    > >>>> information that follows applies to.
    > >>> I'm afraid you're confusing us.
    > >>> Your first sentence says you want to know which variable you used to
    > >>> access an object.
    > >>> Your second sentence says you want to know which object you
    > >>> accessed.
    > >>> Which do you really want?
    > >> It's easy enough to understand once you accept that he's asking for
    > >> something grossly impossible; he wants an object to magically remember
    > >> the name of the first variable it was ever assigned to.

    >
    > > You're guessing. So am I. The trouble is that he knows what answer he's
    > > expecting but doesn't know, or can't describe, what question it's
    > > answering. Until we know the question we don't know which of six
    > > different solutions to suggest.

    >
    > No, actually, I'm really not guessing. He is saying very plainly and
    > unambiguously what it is that he wants; we're just having trouble
    > understanding it because anyone with the slightest knowledge of
    > programming -- in any language -- knows that what he's asking for is
    > complete nonsense, and so our instincts make us want to believe that
    > he's asking for something else, something sensible, instead. Humans are
    > patter-matchers. But if you read his original message, it's very clear
    > that he has gotten the notion into his head that the statement
    >
    > variablename = new objecttype;
    >
    > somehow forges a permanent and bilateral tie between the newly created
    > object and the assigned-to variable -- that the new object is somehow
    > "really" {variablename}, irrespective of whatever other variables it may
    > subsequently be assigned to.


    OP also says: "I need to know which
    object *instance* is being accessed to report for debugging purposes.
    If there's some kind of problem with an object instance, I'd like for
    the instance to be able to report, "Hey, this specific thing has
    something wrong with it. (As opposed to all the other things of the
    same type that you've declared.)".

    So being spelled in the programming terms, OP wants to know:
    1) if there is a way to access instance OID (Object identifier) in
    JavaScript.
    2) if it is so then if there is a way to match the internal OID to the
    higher level execution flow thus to find out what instance with such
    OID matches to one created in the program statements.

    The answer is "No" in both cases. OP is right in his assumption that
    no matter how many reference values to an instance are existing
    runtime - it is always the same heap with the same internal OID. The
    deal is that it is not accessible from the top level and even if it
    was then it is not correlated with top level identifiers.
     
    VK, Dec 1, 2007
    #13
  14. VK wrote:
    > On Dec 1, 8:09 am, "John W. Kennedy" <> wrote:
    >> [...] But if you read his original message, it's very clear
    >> that he has gotten the notion into his head that the statement
    >>
    >> variablename = new objecttype;
    >>
    >> somehow forges a permanent and bilateral tie between the newly created
    >> object and the assigned-to variable -- that the new object is somehow
    >> "really" {variablename}, irrespective of whatever other variables it may
    >> subsequently be assigned to.

    >
    > OP also says: "I need to know which object *instance* is being accessed
    > to report for debugging purposes.


    Objects have identity, not names (unless you give the object a property that
    is its name, as suggested). References can have names, but there can be
    more than one reference to the same object. Which one of those names,
    provided there is one, would you like the method to return?


    PointedEars
    --
    var bugRiddenCrashPronePieceOfJunk = (
    navigator.userAgent.indexOf('MSIE 5') != -1
    && navigator.userAgent.indexOf('Mac') != -1
    ) // Plone, register_function.js:16
     
    Thomas 'PointedEars' Lahn, Dec 1, 2007
    #14
  15. TonyV

    TonyV Guest

    On Dec 1, 12:09 am, "John W. Kennedy" <> wrote:
    > No, actually, I'm really not guessing. He is saying very plainly and
    > unambiguously what it is that he wants; we're just having trouble
    > understanding it because anyone with the slightest knowledge of
    > programming -- in any language -- knows that what he's asking for is
    > complete nonsense...


    This is the last reply I'm going to post because it seems that it
    can't be done in Javascript, but I just had to reply to this that just
    because you apparently don't know a lot about programming is no reason
    to project your inadequacy on others.

    As most people who *actually* have knowledge about programming know,
    almost every language maintains something called a "symbol table" that
    associates names of things with what and where they are. When you say
    something like:
    var foo = 12;

    the symbol table is what associates the memory location that holds the
    value of 12 with the name "foo." Later, if you say:
    foo += 4;

    Javascript uses the symbol table to know what exactly is supposed to
    be incremented by four. I know, this is all pretty sophisticated and
    might seem to work like "magic" as far as you can tell. But I assure
    you, it's *not* magic, it's *not* nonsense, and it usually works
    pretty well behind the scenes with no need to worry much about it.

    However, there might be an occasion--for example, if one were working
    on a debugging function--when it would be handy to have limited access
    to the symbol table, preferably through some mechanism built into the
    language itself instead of through a separate debugging program or
    creating fields to manually store instance names. That way, if some
    function fails on one of a thousand or so object instances within a
    program, the debugging function could say something like, "Hey, the
    foo object is the one that's hosed up" at runtime, making
    troubleshooting the problem much easier.

    Maybe you've never worked with a debugger that has access to programs'
    symbol tables and that can show you this information. I have, but not
    in Javascript, though I'm certain they exist. Maybe you've never
    heard of a stack trace, or think that it really does work by magic
    when it looks like it's pulling the names of calling functions out of
    thin air. I assure you, though, that such concepts aren't nonsense,
    they're extremely practical and used quite frequently by *real*
    programmers.

    All I needed to know is if there's a way to get this information at
    runtime, which from what I've read here, there's not. That's all,
    question answered, no need to be condescending.

    I apologize if my attempt at simplification was confusing. I figured
    that if Javascript did have some mechanism to access the name(s) of
    objects within those objects, it would probably be something
    relatively obvious to someone who's worked with the language for a
    while, and talking about symbol tables and stack traces would have
    been overkill and would have been more confusing, not less.

    I sincerely hope that next time you don't know something, you actually
    try learning a few things when you're out of your league instead of
    treating people who are likely smarter and more experienced than you
    like they're stupid.

    To the others who have posted in this thread, thanks for the input.
    I'll probably just go with VK's original suggestion of manually
    telling new objects what name I've given them.
     
    TonyV, Dec 3, 2007
    #15
  16. TonyV wrote:
    > On Dec 1, 12:09 am, "John W. Kennedy" <> wrote:
    >> No, actually, I'm really not guessing. He is saying very plainly and
    >> unambiguously what it is that he wants; we're just having trouble
    >> understanding it because anyone with the slightest knowledge of
    >> programming -- in any language -- knows that what he's asking for is
    >> complete nonsense...


    > This is the last reply I'm going to post because it seems that it
    > can't be done in Javascript, but I just had to reply to this that just
    > because you apparently don't know a lot about programming is no reason
    > to project your inadequacy on others.


    I've been programming, in dozens of languages, for over forty years.

    > As most people who *actually* have knowledge about programming know,
    > almost every language maintains something called a "symbol table" that
    > associates names of things with what and where they are. When you say
    > something like:
    > var foo = 12;


    "Languages" do no such thing. Interpreters and compilers do, but
    compilers, except in special debug modes, normally discard the
    information long before execution begins.

    > the symbol table is what associates the memory location that holds the
    > value of 12 with the name "foo." Later, if you say:
    > foo += 4;


    > Javascript uses the symbol table to know what exactly is supposed to
    > be incremented by four. I know, this is all pretty sophisticated and
    > might seem to work like "magic" as far as you can tell. But I assure
    > you, it's *not* magic, it's *not* nonsense, and it usually works
    > pretty well behind the scenes with no need to worry much about it.


    That is not an analogy to what you asked for, which was (to continue
    with this example) that the number 12 should somehow remember that its
    name is "foo" -- even after it has been assigned to other variables. You
    explained that that was what you wanted at great length in your original
    post.

    And that /is/ nonsense, and that's why most of the people here couldn't
    even figure out what you wanted; it was too far from reality.

    --
    John W. Kennedy
    "The grand art mastered the thudding hammer of Thor
    And the heart of our lord Taliessin determined the war."
    -- Charles Williams. "Mount Badon"
     
    John W. Kennedy, Dec 3, 2007
    #16
  17. TonyV

    Evertjan. Guest

    TonyV wrote on 03 dec 2007 in comp.lang.javascript:

    > However, there might be an occasion--for example, if one were working
    > on a debugging function--when it would be handy to have limited access
    > to the symbol table, preferably through some mechanism built into the
    > language itself instead of through a separate debugging program or
    > creating fields to manually store instance names.


    This is all very well for a language that has one implementation engine,
    and the so called [by you] symbol table has a reachable position in the
    memory stack or memory address space.

    However Javascript is just a specification, and the actual execution is
    on a wide variatry of implementations, so anything you want to do outside
    of the specs, even if you succede with your own engine will probably fail
    on others. Cross browser friendly that is called in clientside js.

    Even a language like Forth, that can meta-compile it's own kernel engine,
    and has access to the symbol table in specs, has in the years become a
    language with so many flavours, that a general method for such things
    should be tested on each flavour.

    Javascript, having only high level specs, cannot help you in this. And
    Javascript in sensu strictior is just specs.

    > That way, if some
    > function fails on one of a thousand or so object instances within a
    > program, the debugging function could say something like, "Hey, the
    > foo object is the one that's hosed up" at runtime, making
    > troubleshooting the problem much easier.


    In the end, debugging can only be an manual incode affair, setting
    breakpoints or logpoints at strategically correct positions in the code.
    and improving on that by intelligent analysis of repeated trial and
    error.

    Js is a scripting [or runtime compiling] and not a compiler language,
    where the need for adding a symbol table at compiled debug time is much
    stronger, as it's objects [variables, functions, etc.] are nameless at
    user runtime.

    --
    Evertjan.
    The Netherlands.
    (Please change the x'es to dots in my emailaddress)
     
    Evertjan., Dec 3, 2007
    #17
  18. On Mon, 3 Dec 2007 at 14:07:50, in comp.lang.javascript, TonyV wrote:

    <snip>
    >As most people who *actually* have knowledge about programming know,
    >almost every language maintains something called a "symbol table" that
    >associates names of things with what and where they are. When you say
    >something like:
    >var foo = 12;
    >
    >the symbol table is what associates the memory location that holds the
    >value of 12 with the name "foo." Later, if you say:
    >foo += 4;
    >
    >Javascript uses the symbol table to know what exactly is supposed to
    >be incremented by four. I know, this is all pretty sophisticated and
    >might seem to work like "magic" as far as you can tell. But I assure
    >you, it's *not* magic, it's *not* nonsense, and it usually works
    >pretty well behind the scenes with no need to worry much about it.

    <snip>
    >All I needed to know is if there's a way to get this information at
    >runtime, which from what I've read here, there's not. That's all,
    >question answered, no need to be condescending.

    <snip>

    I wish you'd said this earlier so we could explain what the problem is,
    as follows :-


    First, a javascript variable holds a value that is small and primitive,
    whatever type it is. It never holds an object, whatever the appearance
    of the code might suggest. Instead it holds a pointer to the object. The
    object might be at a different address each time the program is run.
    Seeing the value held in the variable is not going to be helpful : it's
    just an address; an address that neither you nor the compiler can
    predict.

    Java is the same by the way.


    Second, the official execution model for javascript says that variables
    are implemented as properties of relevant system objects. An object's
    properties are (name, value) structures held by the object in no
    particular order. A variable needn't have a fixed address. It is found,
    notionally at least, by searching for the name every time it is
    accessed.

    Where other languages have symbol tables inside the compiler linking
    names and addresses, javascript has property collections inside the
    executing program linking names and values.


    It should now be clear that you really were asking the wrong question.

    John
    --
    John Harris
     
    John G Harris, Dec 5, 2007
    #18
    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. Joey
    Replies:
    0
    Views:
    363
  2. =?iso-8859-1?B?bW9vcJk=?=
    Replies:
    7
    Views:
    876
    Roedy Green
    Jan 2, 2006
  3. ding feng
    Replies:
    2
    Views:
    2,879
    ding feng
    Jun 25, 2003
  4. Bobby Chamness
    Replies:
    2
    Views:
    2,426
    Joe Smith
    Apr 22, 2007
  5. Jack-2
    Replies:
    3
    Views:
    309
    Jack-2
    Dec 24, 2003
Loading...

Share This Page