對於同步getter函數命名約定,命名約定是良好定義的:異步吸氣
var getFerby = function(){
..
return ferby;
};
然而,如果我想要的ferby局部不(同步)可用,通常的方法是處理情況有一個回調:
/**
* Asynchronously gets a ferby and passes it to the callback.
*
* Once the ferby is retrieved, these rules MUST be followed:
* 1) Don't feed it after midnight.
* 2) Don't give it water.
* 3) Don't let it near bright light.
*
* @param {ferbyCallback} callback - The callback function that expects a ferby.
*/
var fooFerby = function(callback){
getFerbyLoader().load(function(ferby){
callback(ferby);
});
};
/**
* The callback for the fooFerby function.
*
* @callback ferbyCallback
* @param ferby The ferby
*/
什麼是fooFerby
一個良好的命名約定,這樣我才知道的名字,它預計回調?
我喜歡getFerbyCB,_getFerby,cbGetFerby或getFerbyAsync ... – dandavis
@dandavis感謝您的建議。就我個人而言,我喜歡前綴,因此您只需查看名稱的前面以獲得該函數的一般感受,所以'_getFerby'和'cbGetFerby'就會成爲候選。查看[同義詞獲取](http://thesaurus.com/browse/get),更多的候選人是'acquireFerbie','grabFerby','obtainFerbie','procureFerbie'或(我個人最喜歡的)'fetchFerby' 。我希望爲此制定一個半標準化的命名約定。 – Briguy37