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

best way to teach jslint that I know about the "circular dependencies"

Expand Messages
  • DoNotSay
    I have two functions: function blddrgable() { $j( div.blddrg ).draggable( destroy ).droppable( destroy );
    Message 1 of 4 , Aug 14 5:05 AM
    • 0 Attachment
      I have two functions:

      function blddrgable()
      {
      $j('div.blddrg').draggable("destroy").droppable("destroy");
      $j('div.blddrg').draggable({opacity:0.8,zIndex:8000,helper:"clone"})
      .droppable({accept:'.blddrg',drop:onDropBld});
      }

      function onDropBld (e, ui){

      gboxJSON2("/swapbild",{"von":$j(this).attr("id"),"nach":$j(ui.draggable).attr("id")},function(erg){});
      $j(this).swap($j(ui.draggable));
      blddrgable();
      }

      "blddrgable()" connects function "onDropBld" to the drop-event of some
      .divs. That function does some stuff, and after doing it, it calls
      blddragable again to unbind all previous drop-functions and rebind
      itself to the drop event.

      Now... jslint notifies me, that onDropBld get's "used" before it is
      defined. If I change the order, same result.

      Now, it is totally correct to define these functions this way, because
      on execution of them they both will exist - otherwise there will be no
      drop event handling.

      HOW can I tell jslint that it is okay to be that way?

      My workaround was to write

      /*global onDropBld*/

      but that not exactly says what is going on. Better recommendations?

      best wishes

      Armin
    • Douglas Crockford
      ... gboxJSON2( /swapbild ,{ von :$j(this).attr( id ), nach :$j(ui.draggable).attr( id )},function(erg){}); ... The global trick obviously only works if the
      Message 2 of 4 , Aug 14 7:54 AM
      • 0 Attachment
        --- In jslint_com@yahoogroups.com, "DoNotSay" <arminx@...> wrote:
        >
        > I have two functions:
        >
        > function blddrgable()
        > {
        > $j('div.blddrg').draggable("destroy").droppable("destroy");
        > $j('div.blddrg').draggable({opacity:0.8,zIndex:8000,helper:"clone"})
        > .droppable({accept:'.blddrg',drop:onDropBld});
        > }
        >
        > function onDropBld (e, ui){
        >
        >
        gboxJSON2("/swapbild",{"von":$j(this).attr("id"),"nach":$j(ui.draggable).attr("id")},function(erg){});
        > $j(this).swap($j(ui.draggable));
        > blddrgable();
        > }
        >
        > "blddrgable()" connects function "onDropBld" to the drop-event of some
        > .divs. That function does some stuff, and after doing it, it calls
        > blddragable again to unbind all previous drop-functions and rebind
        > itself to the drop event.
        >
        > Now... jslint notifies me, that onDropBld get's "used" before it is
        > defined. If I change the order, same result.
        >
        > Now, it is totally correct to define these functions this way, because
        > on execution of them they both will exist - otherwise there will be no
        > drop event handling.
        >
        > HOW can I tell jslint that it is okay to be that way?
        >
        > My workaround was to write
        >
        > /*global onDropBld*/
        >
        > but that not exactly says what is going on. Better recommendations?

        The global trick obviously only works if the functions are global.
        Ideally, you should have no more than one global function, so it is
        not a general solution.

        There are two things you can do.

        1) Make gboxJSON2 an inner function of blddrgable.

        2) var gboxJSON2;
        function blddrgable...
        gboxJSON2 = function...
      • DoNotSay
        Douglas, ... gboxJSON2( /swapbild ,{ von :$j(this).attr( id ), nach :$j(ui.draggable).attr( id )},function(erg){}); ... It also works with non-global
        Message 3 of 4 , Aug 16 7:03 AM
        • 0 Attachment
          Douglas,

          > > function blddrgable()
          > > {
          > > $j('div.blddrg').draggable("destroy").droppable("destroy");
          > > $j('div.blddrg').draggable({opacity:0.8,zIndex:8000,helper:"clone"})
          > > .droppable({accept:'.blddrg',drop:onDropBld});
          > > }
          > >
          > > function onDropBld (e, ui){
          >
          gboxJSON2("/swapbild",{"von":$j(this).attr("id"),"nach":$j(ui.draggable).attr("id")},function(erg){});
          > > $j(this).swap($j(ui.draggable));
          > > blddrgable();
          > > }
          > >
          > > "blddrgable()" connects function "onDropBld" to the drop-event of some
          > > .divs. That function does some stuff, and after doing it, it calls
          > The global trick obviously only works if the functions are global.

          It also works with non-global functions, but is an ugly, ugly hack!

          > Ideally, you should have no more than one global function, so it is
          > not a general solution.
          yes. And I am workung hard on restructuring my .js to do exactly that!
          your jslint is of GREAT value and a really really big time saver.

          > 1) Make gboxJSON2 an inner function of blddrgable.
          gboxJSON2 is allready defined outside, so making it inner won't do any
          good.

          > 2) var gboxJSON2;
          > function blddrgable...

          That would be...
          var gboxJSON2;
          function bllddrgabl ... ondrop:onDropBld

          onDropBld=function...

          Is there any price to pay for this declaration? IF yes, which price?

          best wishes,

          Harald
        • Douglas Crockford
          ... It is insignificant.
          Message 4 of 4 , Aug 16 8:18 AM
          • 0 Attachment
            --- In jslint_com@yahoogroups.com, "DoNotSay" <arminx@...> wrote:
            > Is there any price to pay for this declaration? IF yes, which price?

            It is insignificant.
          Your message has been successfully submitted and would be delivered to recipients shortly.