Per le funzioni getter sincroni la convenzione di denominazione è ben definita:Convenzione di denominazione delle getter asincrono
var getFerby = function(){
..
return ferby;
};
Tuttavia, se il ferby desiderata non è localmente (sincrono) disponibile, un metodo comune è quello di gestire tale situazione con un callback:
/**
* 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
*/
cosa è una buona convenzione di denominazione per fooFerby
in modo che io conosco per nome che si aspetta un callback?
mi piace getFerbyCB, _getFerby, cbGetFerby o getFerbyAsync ... – dandavis
@dandavis Grazie per i suggerimenti. Personalmente, mi piacciono i prefissi quindi devi solo guardare la parte anteriore del nome per avere la sensazione generale della funzione, quindi '_getFerby' e' cbGetFerby' sarebbero candidati per questo. Guardando [sinonimi per ottenere] (http://thesaurus.com/browse/get), alcuni più candidati sono 'acquireFerbie',' grabFerby', 'getFerbie',' procureFerbie', o (il mio preferito) 'fetchFerby' . Speravo in una convenzione di denominazione semi-standardizzata per questo. – Briguy37