Coffeescript chaining call

Could not manage call chain using coffee script. I am trying to reproduce this in a coffee script:

function htmlEscape(str) { return String(str) .replace(/&/g, '&amp;') .replace(/"/g, '&quot;') .replace(/'/g, '&#39;') .replace(/</g, '&lt;') .replace(/>/g, '&gt;'); } 

I try like this:

 htmlEscape = (str) -> String(str) .replace (a,b) .replace (c,d) 

gets error Parse error on line 13: Unexpected ',' . Can someone help me with the correct chaining syntax?

+4
source share
1 answer

You should remove these spaces (and possibly put a space after the decimal point):

 htmlEscape = (str) -> String(str) .replace(a, b) .replace(c, d) 

Or:

 htmlEscape = (str) -> String(str). replace(a, b). replace(c, d) 

I like the second one. Note that you can ignore what you are doing using reduce .

+4
source

Source: https://habr.com/ru/post/1386672/


All Articles