我查看了jquery源代码并注意到camelcase是:
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
}
// where:
rmsPrefix = /^-ms-/,
rdashAlpha = /-([\da-z])/gi,
fcamelCase = function( all, letter ) {
return letter.toUpperCase();
}我的问题是:为什么rdashAlpha也要找数字,在数字上打电话有意义吗?有一些unicode字符可以改变吗?
发布于 2013-09-24 00:59:43
如果您注意到,该函数也会删除连字符。不,大写的数字或大写字母不必大写,但函数的目的是用第一个字符替换整个匹配(例如"-2“或"-w”或"-W")。
当然,在任何事情上调用.toUpperCase()都更容易、更干净,而且可能比确定是否调用它更快。
https://stackoverflow.com/questions/18971207
复制相似问题