思路:利用正则表达式的replace方法。
function upper(all,letter){ return letter.toUpperCase(); } let str = 'border-bottom-width'; let res = str.replace(/-(\w)/g,upper); console.log(res);//borderBottomWidth
这个实例中提供了匹配中横线连续字母的正则表达式。upper函数传入的第1个参数是匹配的字符串,第二个参数是捕获(参考《JavaScript忍者秘籍》(第2版))。第一次调用传入的参数是-b和b,第二次调用传入的参数是-w和w。
True courage is about being honest with yourself. Especially when it’s difficult.
真正的勇者能够诚实地面对自己,尤其是当真相很残酷时。