Thursday, 5 September 2013

Downsides & Alternatives - JS method chaining

Downsides & Alternatives - JS method chaining

I am doing something along these lines in some code I am writing
txt =
txt.replaceAll('\n','').replaceAll('<b>','[bold]').replaceAll('</b>','[/bold]')
.replaceAll('<strong>','[bold]').replaceAll('</strong>','[/bold]')....
where replaceAll is a String.prototype extension. This works perfectly,
but I am wondering -
are there any downsides to chaining too many methods in this way? Would it
perhaps be better to use a regex that does the job in a "oner"? If so what
would the regex look like? (I am not terribly good with regexs)

No comments:

Post a Comment