2013-09-24 47 views
1

我一直在尋找在jQuery的來源,發現駝峯是:jQuery的駝峯實施

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也找數字,有沒有呼籲一個數字一個touppercase點?有沒有可以改變的unicode字符?

回答

2

如果您會注意到,該函數還會刪除連字符。不,不需要大寫數字或大寫字母,但該函數旨在用第一個字符替換整個匹配(例如「-2」或「-w」或「-W」)。

調用.toUpperCase()就一切來說肯定更容易,更乾淨,並且可能快於確定是否來調用它。