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

1255Re: [jslint] Formatting of chained functions gives odd results...

Expand Messages
  • Michael Lorton
    Mar 30, 2010
    • 0 Attachment
      This is off-topic -- way, way off-topic -- but the jQuery way of generating DOM nodes from strings (or a mixture of strings and function calls) always struck me as smelly. I wrote a bunch of functions that happen to have the same name as DOM nodes to do the generation instead;

      dom = DIV(DIV({
      'id': content_id,
      'class': 'content',
      style : { width : '100px', height : "200px" },
      DIV({
      'id': results_id,
      'class': 'results'}),
      DIV({
      'id': sponsored_id,
      'class': 'sponsored'})),
      DIV({
      'id': right_sponsored_id,
      'class': 'right_sponsored'
      },
      UL({
      'id': pager_id,
      'class': 'pager'
      })));

      I find it much easier to read -- plus it's possible to get non-programmer designer types to write the code too, because it is so similar to HTML.

      You can find the source here: http://www.circuspop.com/static/js/domination.js

      We now return you to your regularly scheduled JSLint.

      M.







      ________________________________
      From: Dave <david.hampton@...>
      To: jslint_com@yahoogroups.com
      Sent: Tue, March 30, 2010 11:33:26 AM
      Subject: [jslint] Formatting of chained functions gives odd results...

      Chained functions are quite popular and offer some flexibility, with a sometimes lack of readability.

      Currently, JSLint will accept this as accurately indented.

      dom = $('<div/>')
      .append($('<div/>')
      .attr({
      'id': content_id,
      'class': 'content'
      })
      .html($('<div/>')
      .attr({
      'id': results_id,
      'class': 'results'
      })
      .html($('<div/>')
      .attr({
      'id': sponsored_id,
      'class': 'sponsored'
      })))
      .append($('<div/>').attr({
      'id': right_sponsored_id,
      'class': 'right_sponsored'
      })))
      .append($('<ul/>').attr({
      'id': pager_id,
      'class': 'pager'
      }));



      But you and I know that that is hard to read. What about having JSLint optionally allow indenting of functions of no more than the standard indent amount so the above code can look like:

      dom = $('<div/>')
      .append($('<div/>')
      .attr({
      'id': content_id,
      'class': 'content'
      })
      .html($('<div/>')
      .attr({
      'id': results_id,
      'class': 'results'
      })
      .html($('<div/>')
      .attr({
      'id': sponsored_id,
      'class': 'sponsored'
      })
      )
      )
      .append($('<div/>')
      .attr({
      'id': right_sponsored_id,
      'class': 'right_sponsored'
      })
      )
      )
      .append($('<ul/>')
      .attr({
      'id': pager_id,
      'class': 'pager'
      }
      )
      );


      Currently, this baffles JSLint as it asks me to indent things even more than I would like...

      Let me know what you think. That is, should chained functions be allowed an optional indent provided it follows all of the other indenting rules?



      ------------------------------------

      Yahoo! Groups Links



      [Non-text portions of this message have been removed]
    • Show all 6 messages in this topic