+ 1
Hey, guys. Can you explain to me what this line means. Especially the 0, the dollar sign and sign =>
"font-size".replace(/-\w/g, $0 => $0.toUpperCase());
2 ответов
+ 3
It means capitalize letters immediately following a minus/hyphen sign.
This example makes the regular expression behaviour more clear:
"font-size world -yo".replace(/-\w/g, $0 => $0.toUpperCase());
"font-Size world -Yo"
Here is a more detailed look at your replace call:
\w means word character. In other words the letters in [a-z].
For every occurrence of a - sign followed by a letter, convert to upper case. The "$0 => $0.toUpperCase()" is a function with no name expressed with the arrow syntax. $0 is the string that matched the regular expression pattern. $0 could be something like "-s". The $0 could be named whatever you want. "matchString" would have been more descriptive.
0
Josh, thank you