jQuery(反)模式:使用字符串操作构建选择器 [英] jQuery (anti-)pattern: building selectors with string manipulation

查看:157
本文介绍了jQuery(反)模式:使用字符串操作构建选择器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



好还是坏?

/ strong>

解决方案

那是什么问题?什么是替代品 - 只是将它们编码为单个字符串?但是,您可以在网站上使用约定如何组织布局。如果您只是将选择器组件定义在一个位置,并使用它来构建一个选择器,听起来像这样做不会比通过所有代码更麻烦,并且在其显示的任何地方进行搜索替换。



我会说这是很好的,假设你有其他组织的字符串(在一个地方定义,在几个地方使用)。


Too often I find myself building selectors with string manipulation (split, search, replace, concat, +, join).

Good or bad?

解决方案

What's wrong with that? What are the alternatives — just hardcoding them as single strings? But you may use conventions on your site for how the layout is organized. If you just define the selector components in one place, and use it to build a selector, sounds like this would be less hassle than going through all the code and doing search-replace everywhere it shows up.

I'd say it's good assuming you have the strings otherwise organized (defined in one place, used in several places).

这篇关于jQuery(反)模式:使用字符串操作构建选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆