FunctionExpression's and memory consumptions

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

    #16
    Re: FunctionExpress ion's and memory consumptions

    On Nov 1, 2:24 am, Conrad Lender <crlen...@yahoo .comwrote:
    On 2008-10-31 08:21, Jorge wrote:
    >
    No no it's not so. Any function declaration inside an inner block is
    considered an error and ignored (in Mozillas).
    >
    They're not ignored. Try the function in my previous post and see if you
    get an alert.
    (...)
    I'm not sure how this is relevant - nothing in that thread suggests that
    Mozilla discards function declarations in a block.
    Try this:

    <script>
    window.onload= function () {
    function foo () { alert('outer'); }
    if (true) {
    function foo () { alert('inner'); }
    }
    foo();
    };
    </script>

    Mozillas: -outer
    Everywhere else: -inner

    --
    Jorge.

    Comment

    • Jorge

      #17
      Re: FunctionExpress ion's and memory consumptions

      On Nov 1, 9:42 am, Jorge <jo...@jorgecha morro.comwrote:
      On Nov 1, 2:24 am, Conrad Lender <crlen...@yahoo .comwrote:
      >
      On 2008-10-31 08:21, Jorge wrote:
      >
      No no it's not so. Any function declaration inside an inner block is
      considered an error and ignored (in Mozillas).
      >
      They're not ignored. Try the function in my previous post and see if you
      get an alert.
      (...)
      I'm not sure how this is relevant - nothing in that thread suggests that
      Mozilla discards function declarations in a block.
      >
      Try this:
      >
      <script>
      window.onload= function () {
        function foo () { alert('outer'); }
        if (true) {
          function foo () { alert('inner'); }
        }
        foo();};
      >
      </script>
      >
      Mozillas: -outer
      Everywhere else: -inner
      Note that changing if (true) to if (false) doesn't make any
      difference.

      --
      Jorge.

      Comment

      • Jorge

        #18
        Re: FunctionExpress ion's and memory consumptions

        On Nov 1, 2:24 am, Conrad Lender <crlen...@yahoo .comwrote:
        On 2008-10-31 08:21, Jorge wrote:
        >
        No no it's not so. Any function declaration inside an inner block is
        considered an error and ignored (in Mozillas).
        >
        They're not ignored. Try the function in my previous post and see if you
        get an alert.
        (...)
        I'm not sure how this is relevant - nothing in that thread suggests that
        Mozilla discards function declarations in a block.
        Try this:

        <script>
        window.onload= function () {
        function foo () { alert('outer'); }
        if (true) {
        function foo () { alert('inner'); }
        }
        foo();
        };
        </script>

        Mozillas: -outer
        Everywhere else: -inner

        --
        Jorge.

        Comment

        • Jorge

          #19
          Re: FunctionExpress ion's and memory consumptions

          On Nov 1, 9:42 am, Jorge <jo...@jorgecha morro.comwrote:
          On Nov 1, 2:24 am, Conrad Lender <crlen...@yahoo .comwrote:
          >
          On 2008-10-31 08:21, Jorge wrote:
          >
          No no it's not so. Any function declaration inside an inner block is
          considered an error and ignored (in Mozillas).
          >
          They're not ignored. Try the function in my previous post and see if you
          get an alert.
          (...)
          I'm not sure how this is relevant - nothing in that thread suggests that
          Mozilla discards function declarations in a block.
          >
          Try this:
          >
          <script>
          window.onload= function () {
            function foo () { alert('outer'); }
            if (true) {
              function foo () { alert('inner'); }
            }
            foo();};
          >
          </script>
          >
          Mozillas: -outer
          Everywhere else: -inner
          Note that changing if (true) to if (false) doesn't make any
          difference.

          --
          Jorge.

          Comment

          • kangax

            #20
            Re: FunctionExpress ion's and memory consumptions

            On Nov 1, 3:55 am, Jorge <jo...@jorgecha morro.comwrote:
            On Nov 1, 9:42 am, Jorge <jo...@jorgecha morro.comwrote:
            [...]
            Try this:
            >
            <script>
            window.onload= function () {
              function foo () { alert('outer'); }
              if (true) {
                function foo () { alert('inner'); }
              }
              foo();};
            >
            </script>
            >
            Mozillas: -outer
            Everywhere else: -inner
            >
            Note that changing if (true) to if (false) doesn't make any
            difference.
            It's interesting to observe FunctionStateme nt's (if we can call it
            that way) behavior. From what I can see:

            1) FunctionStateme nt's do not overwrite variables declared via
            FunctionDeclara tion's
            2) FunctionStateme nt's are not declared when enclosing block is being
            entered (but only when a statement is being evaluated)
            3) Once declared, FunctionStateme nt's are available to the entire
            function scope (enclosing one), even outside of an actual block (in
            which it was evaluated).
            4) One FunctionStateme nt can overwrite another FunctionStateme nt with
            the same identifier.

            Tested in: Firefox 3.0.3; Mac OS X 10.5

            function write(s) {
            document.write( s + '<br>');
            }

            (function(){

            function f(){ return 'outer' };

            if (true) {
            write(
            'typeof g (before FunctionStateme nt) ' +
            (typeof g)
            ); // undefined

            function g(){ return 'inner' };

            write(
            'typeof g (after FunctionStateme nt) ' +
            (typeof g)
            ); // function

            write('g() ' + g()); // inner

            write('delete g ' + (delete g)); // false
            write(
            'typeof g (after deletion) ' +
            (typeof g)
            ); // function

            function g(){ return 'inner2' }
            write(
            'g() (second FunctionStateme nt with the same identifier) ' +
            g()
            ); // inner2

            function f(){ return 'inner' }
            write(
            'f() (after FunctionStateme nt named as '+
            'FunctionDeclar ation outside of enclosing block) ' +
            f()
            ); // outer
            }

            write(
            'typeof g (outside of block in which it was declared) ' +
            (typeof g)
            ); // function
            write(
            'g() (outside of block in which it was declared) ' +
            g()
            ); // inner2

            })();
            >
            --
            Jorge.
            --
            kangax

            Comment

            Working...