Loading ...
Sorry, an error occurred while loading the content.

RE: [jslint] Mutual Recursion

Expand Messages
  • Alexandre Morgaut
    With the difference that in the first way the function b is declared in the scope of function a Whereas in the second way function a and b are in the same
    Message 1 of 4 , Mar 11, 2009
    • 0 Attachment
      With the difference that in the first way the function b is declared in the scope of function a
      Whereas in the second way function a and b are in the same scope
      (with indentation it would have clearer)

      To: jslint_com@yahoogroups.com
      From: douglas@...
      Date: Tue, 10 Mar 2009 20:09:38 +0000
      Subject: [jslint] Mutual Recursion





















      A robust coding style demands that symbols should be declared before they are used. But how is this possible in the case of mutually recursive functions? If function a calls function b, and if function b calls function a, how can a and b both be declared before they are used?



      JavaScript provides two ways.



      var a = function () {

      var b = function () {

      ... a() ...

      };

      ... b() ...

      };



      var a;

      var b = function () {

      ... a() ...

      };

      a = function () {

      ... b() ...

      };






















      _________________________________________________________________
      Téléphonez gratuitement à tous vos proches avec Windows Live Messenger  !  Téléchargez-le maintenant ! 
      http://www.windowslive.fr/messenger/1.asp

      [Non-text portions of this message have been removed]
    • Jakob Kruse
      The way I read this, in the first example the function ‘b’ is recreated (which would take time) every time ‘a’ is called. Strictly speaking you would
      Message 2 of 4 , Mar 11, 2009
      • 0 Attachment
        The way I read this, in the first example the function ‘b’ is recreated (which would take time) every time ‘a’ is called. Strictly speaking you would never call the same ‘b’ function twice, but a new one each time. Or is that incorrect?

        For that reason alone I would never use the first example.

        /Jakob


        From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On Behalf Of Alexandre Morgaut
        Sent: 11. marts 2009 14:17
        To: jslint_com@yahoogroups.com
        Subject: RE: [jslint] Mutual Recursion



        With the difference that in the first way the function b is declared in the scope of function a
        Whereas in the second way function a and b are in the same scope
        (with indentation it would have clearer)

        To: jslint_com@yahoogroups.com
        From: douglas@...
        Date: Tue, 10 Mar 2009 20:09:38 +0000
        Subject: [jslint] Mutual Recursion

        A robust coding style demands that symbols should be declared before they are used. But how is this possible in the case of mutually recursive functions? If function a calls function b, and if function b calls function a, how can a and b both be declared before they are used?

        JavaScript provides two ways.

        var a = function () {

        var b = function () {

        ... a() ...

        };

        ... b() ...

        };

        var a;

        var b = function () {

        ... a() ...

        };

        a = function () {

        ... b() ...

        };










        __________________________________________________________
        Téléphonez gratuitement à tous vos proches avec Windows Live Messenger ! Téléchargez-le maintenant !
        http://www.windowslive.fr/messenger/1.asp

        [Non-text portions of this message have been removed]


        [Non-text portions of this message have been removed]
      • Alexandre Morgaut
        I agree with you Jakob For myself I may have declared the function with an empty function var a = function() {}; So that : - a validator which would check then
        Message 3 of 4 , Mar 11, 2009
        • 0 Attachment
          I agree with you Jakob
          For myself I may have declared the function with an empty function


          var a = function() {};

          So that :
          - a validator which would check then var type wouldn't be surprised
          - the developer knows what a is supposed to be (even if it should be evident from a good naming convention and good comments)

          To: jslint_com@yahoogroups.com
          From: kruse@...
          Date: Wed, 11 Mar 2009 14:29:44 +0100
          Subject: RE: [jslint] Mutual Recursion





















          The way I read this, in the first example the function �b� is recreated (which would take time) every time �a� is called. Strictly speaking you would never call the same �b� function twice, but a new one each time. Or is that incorrect?



          For that reason alone I would never use the first example.



          /Jakob





          From: jslint_com@yahoogroups.com [mailto:jslint_com@yahoogroups.com] On Behalf Of Alexandre Morgaut

          Sent: 11. marts 2009 14:17

          To: jslint_com@yahoogroups.com

          Subject: RE: [jslint] Mutual Recursion





          With the difference that in the first way the function b is declared in the scope of function a

          Whereas in the second way function a and b are in the same scope

          (with indentation it would have clearer)



          To: jslint_com@yahoogroups.com

          From: douglas@...

          Date: Tue, 10 Mar 2009 20:09:38 +0000

          Subject: [jslint] Mutual Recursion



          A robust coding style demands that symbols should be declared before they are used. But how is this possible in the case of mutually recursive functions? If function a calls function b, and if function b calls function a, how can a and b both be declared before they are used?



          JavaScript provides two ways.



          var a = function () {



          var b = function () {



          ... a() ...



          };



          ... b() ...



          };



          var a;



          var b = function () {



          ... a() ...



          };



          a = function () {



          ... b() ...



          };



          __________________________________________________________

          T�l�phonez gratuitement � tous vos proches avec Windows Live Messenger ! T�l�chargez-le maintenant !

          http://www.windowslive.fr/messenger/1.asp



          [Non-text portions of this message have been removed]



          [Non-text portions of this message have been removed]






















          _________________________________________________________________
          T�l�phonez gratuitement � tous vos proches avec Windows Live Messenger� !� T�l�chargez-le maintenant !
          http://www.windowslive.fr/messenger/1.asp

          [Non-text portions of this message have been removed]
        Your message has been successfully submitted and would be delivered to recipients shortly.