对于同步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的良好命名约定,以便我知道它希望回调?
最佳答案
我使用前缀“fetch”,而不是异步getter的“get”.
原文链接:https://www.f2er.com/js/429767.html这个想法是,如果它不是本地可用的,你需要获取它.