变量名处理的思路整理:
1.将字符分割为数组,map是对象的方法
2.map返回处理的数据
3.(item是字符串类型)利用字符串的伪数组特性
<script>
//变量名的处理采用es5新增map(),传递回调函数,回调函数里面return修改的值
// var msg = 'get-element-by-id';
// var ar = msg.split('-').map(function(item,index){
// if( index===0 ){
// return item
// }
// return item[0].toUpperCase() + item.slice(1)
// }).join('')
// console.log(ar)
//看的懂上面就地封装一个函数
console.log(cemal('get-element-by-id'))
function cemal(varName){
return varName.split('-').map(function(item,index){
if( index===0 ){
return item
}
return item[0].toUpperCase() + item.slice(1)
}).join('')
}
</script>