开发者

How can I get rid of $ prefixes in my variable names with jQuery?

I started off naming my jQuery objects like $this.

Then, I decided I didn't want to do it anymore.

I just borrowed a large chunk of code fro开发者_JS百科m an old project. It is from the $ prefix days, and it is irking me!

What regex can I use in my IDE to get rid of the $ prefixes on my variables?


To do it right, you will have to parse the javascript and replace only identifiers and not literals. Of course, it may not be worth the effort if your codebase is pretty small.

There are a few javascript parsers out there - ANTLR, google closure compiler and JS lint may have an implementation.


Try this...

/\$(?!\()/

...and obviously replace with an empty string ''.

This has some pretty serious limitations, but if you don't have a abundance of strings which may contain this pattern, it is good enough.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜