Re: anonymous functions; naming of and firebug

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • dhtml

    Re: anonymous functions; naming of and firebug

    On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
    wrote:
    mk83...@yahoo.c om wrote:
    anchors[ndx].onclick = function aname() {
    >
    Firebug still lists an anonymous function. Is there a way to assign a
    name?
    >
    You have assigned a name with the above, but Firebug never shows the name.
    That should not come as a surprise because a) the name is only locally
    available (except in JScript) and b) functions don't have a certain name in
    the greater context.
    In Spidermonkey Functions absolutely do have a name:-

    var x = function y() {
    console.log(arg uments.callee.n ame);
    };

    x();

    Result: y

    As for the problem of inspecting the LI, logging it should have the
    effect:

    console.log( li );


    Garrett

    [snip]
    PointedEars
  • Thomas 'PointedEars' Lahn

    #2
    Re: anonymous functions; naming of and firebug

    dhtml wrote:
    On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
    wrote:
    >mk83...@yahoo. com wrote:
    >> anchors[ndx].onclick = function aname() {
    >>Firebug still lists an anonymous function. Is there a way to assign a
    >>name?
    >You have assigned a name with the above, but Firebug never shows the name.
    >That should not come as a surprise because a) the name is only locally
    >available (except in JScript) and b) functions don't have a certain name in
    >the greater context.
    >
    In Spidermonkey Functions absolutely do have a name:-
    You miss the point. I have said that Functions do _not_ have a *certain*
    name in the greater context. That really is basic knowledge:
    var x = function y() {
    console.log(arg uments.callee.n ame);
    };
    >
    x();
    >
    Result: y
    See? Would you really expect the function to be displayed as `y' despite
    the property that is referring to it has the name `x'?

    And what about

    o.z = function y() {
    console.log(arg uments.callee.n ame);
    returns false;
    };

    Would you then expect Firebug displaying `y' as well despite `o.z' refers to
    a completely different Function object? Most certainly not.
    As for the problem of inspecting the LI, logging it should have the
    effect:
    >
    console.log( li );
    That will of course display only the start tag of the element, a string
    representation of the element node and its attribute nodes. Since `onclick'
    is an attribute in the markup but not accessed as such here (else you would
    assign a string value and not a Function object reference), there is no
    change in its representation. (If one used setAttribute(), the change would
    be visible in Firebug, but the script would not be likely to work everywhere.)


    PointedEars
    --
    Prototype.js was written by people who don't know javascript for people
    who don't know javascript. People who don't know javascript are not
    the best source of advice on designing systems that use javascript.
    -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

    Comment

    • dhtml

      #3
      Re: anonymous functions; naming of and firebug

      On Apr 14, 12:24 pm, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
      wrote:
      dhtml wrote:
      On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
      wrote:
      mk83...@yahoo.c om wrote:
      > anchors[ndx].onclick = function aname() {
      >Firebug still lists an anonymous function. Is there a way to assign a
      >name?
      You have assigned a name with the above, but Firebug never shows the name.
      That should not come as a surprise because a) the name is only locally
      available (except in JScript) and b) functions don't have a certain name in
      the greater context.
      >
      In Spidermonkey Functions absolutely do have a name:-
      >
      You miss the point. I have said that Functions do _not_ have a *certain*
      name in the greater context. That really is basic knowledge:
      >
      var x = function y() {
      console.log(arg uments.callee.n ame);
      };
      >
      x();
      >
      Result: y
      >
      See? Would you really expect the function to be displayed as `y' despite
      the property that is referring to it has the name `x'?
      It doesn't have a name x. x is a reference to a function. That
      function has a name property, with the value y. The name property
      reflects the function's identifier.

      It is entirely possible to have more than one variable point to the
      same function. For example:

      var a = [], z;
      z = a[0] = function y(){};

      I would not expect the function's name to be a[0].

      >
      And what about
      >
      o.z = function y() {
      console.log(arg uments.callee.n ame);
      returns false;
      };
      >
      Would you then expect Firebug displaying `y' as well despite `o.z' refers to
      a completely different Function object? Most certainly not.
      The function that o.z points to has a name. The name is y. It seems to
      me to be a natural expectation that function.name would return the
      identifier of the function.

      It also is a good idea to give a meaningful and unique name to the
      function. Of course, the problem with adding an identifier is that old
      JScript bug. There's also been some bugs in versions of Safari as
      recent as 2.
      >
      As for the problem of inspecting the LI, logging it should have the
      effect:
      >
      console.log( li );
      >
      That will of course display only the start tag of the element, a string
      representation of the element node and its attribute nodes.
      That is what clicking on it is for.

      Since `onclick'
      is an attribute in the markup but not accessed as such here (else you would
      assign a string value and not a Function object reference), there is no
      change in its representation. (If one used setAttribute(), the change would
      be visible in Firebug, but the script would not be likely to work everywhere.)
      >


      PointedEars
      --
      Prototype.js was written by people who don't know javascript for people
      who don't know javascript. People who don't know javascript are not
      the best source of advice on designing systems that use javascript.
      -- Richard Cornford, cljs, <f806at$ail$1$8 300d...@news.de mon.co.uk>

      Comment

      • Thomas 'PointedEars' Lahn

        #4
        Re: anonymous functions; naming of and firebug

        dhtml wrote:
        [...] Thomas 'PointedEars' Lahn [...] wrote:
        >dhtml wrote:
        >>On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
        >>wrote:
        >>>mk83...@yaho o.com wrote:
        >>>> anchors[ndx].onclick = function aname() {
        >>>>Firebug still lists an anonymous function. Is there a way to assign a
        >>>>name?
        >>>You have assigned a name with the above, but Firebug never shows the name.
        >>>That should not come as a surprise because a) the name is only locally
        >>>available (except in JScript) and b) functions don't have a certain name in
        >>>the greater context.
        >>In Spidermonkey Functions absolutely do have a name:-
        >You miss the point. I have said that Functions do _not_ have a *certain*
        >name in the greater context. That really is basic knowledge:
        >>
        >>var x = function y() {
        >> console.log(arg uments.callee.n ame);
        >>};
        >>x();
        >>Result: y
        >See? Would you really expect the function to be displayed as `y' despite
        >the property that is referring to it has the name `x'?
        >
        It doesn't have a name x. x is a reference to a function.
        *yawn*

        To a Function object. I know. You miss the point again.
        That function has a name property, with the value y.
        In one implementation.
        The name property reflects the function's identifier.
        As an ECMAScript extension, it stores the name of a locally available property:

        ,-[ECMAScript Ed. 3 Final, section 13]
        |
        | NOTE The Identifier in a FunctionExpress ion can be referenced from inside
        | the FunctionExpress ion's FunctionBody to allow the function to call itself
        | recursively. However, unlike in a FunctionDeclara tion, the Identifier in
        | a FunctionExpress ion cannot be referenced from and does not affect the
        | scope enclosing the FunctionExpress ion.
        It is entirely possible to have more than one variable point to the
        same function.
        I know. That is exactly one of my points. You cannot expect Firebug to
        display the name there.
        >And what about
        >>
        > o.z = function y() {
        > console.log(arg uments.callee.n ame);
        > returns false;
        > };
        >>
        >Would you then expect Firebug displaying `y' as well despite `o.z' refers to
        >a completely different Function object? Most certainly not.
        >
        The function that o.z points to has a name. The name is y. It seems to
        me to be a natural expectation that function.name would return the
        identifier of the function.
        It would be nonsense for Firebug's DOM inspector to display the same name
        for different Function objects just because they happen to have a locally
        available property with the same name. For example, it would lead to all
        kinds of confusion if an object had

        o.onclick = function x() { return true; };
        o.onmouseup = function x() { return false; };

        and Firebug's DOM inspector were to display

        onclick x()
        onmouseup x()

        instead of what it currently displays:

        onclick function()
        onmouseup function()

        The name property of a Function object, if it has one, is completely
        irrelevant outside its local execution context.
        It also is a good idea to give a meaningful and unique name to the
        function.
        It is in a function declaration, not in a function expression.
        Of course, the problem with adding an identifier is that old
        JScript bug.
        Therefore, it is not a good idea.
        There's also been some bugs in versions of Safari as recent as 2.
        Therefore, it is an even worse idea.
        >>As for the problem of inspecting the LI, logging it should have the
        >>effect:
        >>console.log ( li );
        >That will of course display only the start tag of the element, a string
        >representati on of the element node and its attribute nodes.
        >
        That is what clicking on it is for.
        Have you ever done that for an object that has an event listener added?


        PointedEars
        --
        Prototype.js was written by people who don't know javascript for people
        who don't know javascript. People who don't know javascript are not
        the best source of advice on designing systems that use javascript.
        -- Richard Cornford, cljs, <f806at$ail$1$8 300dec7@news.de mon.co.uk>

        Comment

        • Lasse Reichstein Nielsen

          #5
          Re: anonymous functions; naming of and firebug

          dhtml <dhtmlkitchen@g mail.comwrites:
          > o.z = function y() {
          ....
          The function that o.z points to has a name. The name is y. It seems to
          me to be a natural expectation that function.name would return the
          identifier of the function.
          That would have been a reasonable design. Alas, it isn't so. There
          is no direct way to access that name from outside its scope. Its
          scope is the body of the function.

          On the other hand, it's also completely useless outside of its scope,
          for anything but documentation purposes, so it's no big loss in
          practice.

          /L
          --
          Lasse Reichstein Nielsen - lrn@hotpop.com
          DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
          'Faith without judgement merely degrades the spirit divine.'

          Comment

          • dhtml

            #6
            Re: anonymous functions; naming of and firebug

            On Apr 16, 3:07 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
            wrote:
            dhtml wrote:
            [...] Thomas 'PointedEars' Lahn [...] wrote:
            dhtml wrote:
            >On Feb 17, 4:58 am, Thomas 'PointedEars' Lahn <PointedE...@we b.de>
            >wrote:
            >>mk83...@yahoo .com wrote:
            >>>     anchors[ndx].onclick = function  aname() {

            The spec does not contain a - name - property for a function object.
            It's there in Spidermonkey.
            >
            It would be nonsense for Firebug's DOM inspector to display the same name
            for different Function objects just because they happen to have a locally
            available property with the same name.  For example, it would lead to all
            kinds of confusion if an object had
            >
              o.onclick = function x() { return true; };
              o.onmouseup = function x() { return false; };
            >
            and Firebug's DOM inspector were to display
            >
              onclick    x()
              onmouseup  x()
            >
            instead of what it currently displays:
            >
              onclick    function()
              onmouseup  function()
            >
            The name property of a Function object, if it has one, is completely
            irrelevant outside its local execution context.
            >
            It works in Spidermonkey. When I try this in Firebug, I can see that
            the name - y - will get printed out. It's possibly a different version
            of Firebug.

            document.body.o nclick = function y(){};
            document.body

            This displays in Firebug:
            "<body>"

            When I click on that <body>, then choose the right-side DOM tab, I can
            see
            onclick y()

            For me, that makes it easier to debug.

            It's possible that I could have two functions with y, but I would
            probably not do that. If I did, I'd still ahve it narrowed down to two
            functions in the search result.

            >
            PointedEars
            --
            Prototype.js was written by people who don't know javascript for people
            who don't know javascript. People who don't know javascript are not
            the best source of advice on designing systems that use javascript.
              -- Richard Cornford, cljs, <f806at$ail$1$8 300d...@news.de mon.co.uk>- Hide quoted text -
            >
            - Show quoted text -

            Comment

            Working...