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

Formatting of chained functions gives odd results...

Expand Messages
  • Dave
    Chained functions are quite popular and offer some flexibility, with a sometimes lack of readability. Currently, JSLint will accept this as accurately
    Message 1 of 6 , Mar 30, 2010
    View Source
    • 0 Attachment
      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?
    • Dave
      Well, crap... It looks like the groups formatter got rid of all my formatting in my example. There are lots of nice indents in the second one which make a
      Message 2 of 6 , Mar 30, 2010
      View Source
      • 0 Attachment
        Well, crap... It looks like the groups formatter got rid of all my formatting in my example. There are lots of nice indents in the second one which make a lot of sense. Unfortunately, you can only see them when you reply. So even if you don't want to reply and just want to see the proposed indentation, hit the reply button. Hopefully, quoting this post will allow you to see it....

        --- In jslint_com@yahoogroups.com, "Dave" <david.hampton@...> wrote:
        >
        > 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?
        >
      • Marcel Duran
        Under Show Message Info , click Use Fixed Width Font or use this link: http://tech.groups.yahoo.com/group/jslint_com/message/1252?var=0
        Message 3 of 6 , Mar 30, 2010
        View Source
        • 0 Attachment
          Under "Show Message Info", click "Use Fixed Width Font"

          or use this link:
          http://tech.groups.yahoo.com/group/jslint_com/message/1252?var=0

          <http://tech.groups.yahoo.com/group/jslint_com/message/1252?var=0>where
          var=0 means use fixed width font and var=1 means use variable width font


          Marcel

          On Tue, Mar 30, 2010 at 11:40 AM, Dave <david.hampton@...> wrote:

          >
          >
          > Well, crap... It looks like the groups formatter got rid of all my
          > formatting in my example. There are lots of nice indents in the second one
          > which make a lot of sense. Unfortunately, you can only see them when you
          > reply. So even if you don't want to reply and just want to see the proposed
          > indentation, hit the reply button. Hopefully, quoting this post will allow
          > you to see it....
          >
          >
          > --- In jslint_com@yahoogroups.com <jslint_com%40yahoogroups.com>, "Dave"
          > <david.hampton@...> wrote:
          > >
          > > 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?
          > >
          >
          >
          >



          --
          Marcel Duran


          [Non-text portions of this message have been removed]
        • Michael Lorton
          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
          Message 4 of 6 , Mar 30, 2010
          View Source
          • 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]
          • Dave
            Very Clever Mr. Lorton. I like that very much. Dave
            Message 5 of 6 , Mar 30, 2010
            View Source
            • 0 Attachment
              Very Clever Mr. Lorton. I like that very much.

              Dave

              --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
              >
              > 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.
              >
            • Michael Lorton
              It s not completely original -- I got the idea from a little-used area of MochiKit -- but I would like to publicize it. If anyone can suggest an easy way to
              Message 6 of 6 , Mar 31, 2010
              View Source
              • 0 Attachment
                It's not completely original -- I got the idea from a little-used area of MochiKit -- but I would like to publicize it. If anyone can suggest an easy way to tell a lot of people, hey, here's a really easy way to do something you really have to do a lot, I'm open to suggestions.

                M.





                ________________________________
                From: Dave <david.hampton@...>
                To: jslint_com@yahoogroups.com
                Sent: Tue, March 30, 2010 1:52:31 PM
                Subject: Re: [jslint] Formatting of chained functions gives odd results...

                Very Clever Mr. Lorton. I like that very much.

                Dave

                --- In jslint_com@yahoogroups.com, Michael Lorton <mlorton@...> wrote:
                >
                > 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.
                >




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

                Yahoo! Groups Links



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