是否有一种格式化 jQuery 链以使其更具可读性的首选方法?
给出以下示例代码,该代码克隆表行,设置一些属性,然后将其附加到表中:
$("#FundTable").append(
objButton.parents("tr").clone()
.find(".RowTitle").text("Row " + nAddCount).end()
.find(".FundManagerSelect").attr("id", "FundManager" + nAddCount)
.change(function() { ChangeFundRow(); }).end()
.find(".FundNameSelect").attr("id", "FundName" + nAddCount).end()
);
有没有人对如何格式化它以使其更容易阅读有任何建议?这样做有任何公认的惯例吗?
拥有一套可以遵循并可以纳入一组标准的规则将很有用。
Given this following sample code which clones a table row, sets some properties and then appends it to a table:
$("#FundTable").append(
objButton.parents("tr").clone()
.find(".RowTitle").text("Row " + nAddCount).end()
.find(".FundManagerSelect").attr("id", "FundManager" + nAddCount)
.change(function() { ChangeFundRow(); }).end()
.find(".FundNameSelect").attr("id", "FundName" + nAddCount).end()
);
Does anyone have any suggestions as to how this might be formatted to be easier on the eye? Is there any accepted convention for doing this?
It would be useful to have a set of rules that can be followed, and that can be incorporated into a set of standards.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
我会对此进行重构。我发现超过 3 个连锁方法看起来不太舒服
I would refactor to this. I find more than 3 chained methods uneasy on the eye
我缩进就好像它被括起来一样:
I indent as if it were bracketed:
怎么样:
我发现,在适度使用链接时,可以带来更好的可读性。
How about:
I find that chaining, when used in moderation, can lead to better readability.
别挂那么多。
更少的链接,但在我看来似乎更容易阅读。
Don't chain so much.
Less chaining, but it seems easier to read imo.