參數命名風格轉換

camelize方法,轉換爲駝峯命名風格:javascript

function camelize (target) {
        if (target.indexOf('_') < 0 && target.indexOf('_') < 0) return target; 
        return target.replace(/[-_][^-_]/g , function(match){
            return match[1].toUpperCase();
        })
    }

underscored方法,轉換爲下劃線風格:java

function underscored(target){
        return target.replace(/([a-z\d])([A-Z])/g , '$1_$2').replace(/\-/g , '_').toLowerCase();
    }
相關文章
相關標籤/搜索