/* *已知有字符foo="get-element-by-id",写一个function将其转换成驼峰表示法"getElementById" */ var o = { trans:function (msg){ var i, tempArr = msg.split('-'), len = tempArr.length; for(i = 1; i < len; i++){ tempArr[i] = tempArr[i].charAt(0).toUpperCase()+tempArr[i].substr(1,tempArr[i].length-1); } msg = tempArr.join(''); return msg; } }; o.trans('get-element-by-id');
測试: