jQuery源码分析: 驼峰式命名方法jQuery.camelCase
// Matches dashed string for camelizing 匹配由虚线分割的字符串并改成驼峰式命名法
var rdashAlpha = /-([a-z]|[0-9])/ig,
rmsPrefix = /^-ms-/,
// Used by jQuery.camelCase as callback to replace()
fcamelCase = function( all, letter ) {
return ( letter + "" ).toUpperCase();
};
camelCase: function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
},
举例:
var rdashAlpha = /-([a-z]|[0-9])/ig,
rmsPrefix = /^-ms-/;
// Used by jQuery.camelCase as callback to replace()
var fcamelCase = function( all, letter ) {
return ( letter + "" ).toUpperCase();
};
var camelCase = function( string ) {
return string.replace( rmsPrefix, "ms-" ).replace( rdashAlpha, fcamelCase );
};
alert(camelCase("hello-world-baby"));//< 输出"helloWorldBaby"