从这个api的命名我们很直观地就应该知道是首字母大写的操作。
直接上代码吧。
里面也有String.charAt的相关操作,可以看看我写的这个:http://zhangyaochun.iteye.com/blog/1475764
/* 思路还是很简单的,第一个字符大写,其他都小写 */ capitalize:function(){ return this.charAt(0).toUpperCase() + this.substring(1).toLowerCase(); }
举例:
'zhangyaochun'.capitalize() // 'Zhangyaochun'