[英]Return new promise Q in ternary condition
Im using the following code which is working OK. 我正在使用下面的代码,它可以正常工作。
Now I need to return promise resolve but not sure how to do it in this case, there is nice way to do it? 现在,我需要返回promise resolve,但不确定在这种情况下如何执行,有很好的方法吗? please ignore that the code is sync we are working on a tool which every external API method s hould return promise
请忽略代码是否同步,我们正在开发一种工具,每个外部API方法都应返回promise
This is the code 这是代码
getExtendedFileContent: function(sHTML, aConfig) {
var oDeferred = Q.defer();
return aConfig ? this._process(sHTML, aConfig) : sHTML;
},
the this._process(sHTML, aConfig)
& the sHTML
should return 在
this._process(sHTML, aConfig)
及中sHTML
应该返回
oDeferred.promise;
oDeferred.promise;
Don't use Q.defer
. 不要使用
Q.defer
。 Just use the Q
function (or Promise.resolve
if you're working with an ES6-compatible promise libary): 只需使用
Q
函数 (或Promise.resolve
如果您使用的是与ES6兼容的promise库):
function getExtendedFileContent(sHTML, aConfig) {
return Q(aConfig ? this._process(sHTML, aConfig) : sHTML);
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.