我应该使用 $q 中的私有属性 $$state 来满足我的需要吗?

Should i use private properties $$state in $q for my needs?

使用 angular $q,我在问自己是否应该使用 $$state 私有属性来检查承诺的状态(检查它是待处理还是已完成)。

假设这样的情况:

var promise = undefined;
$scope.click = function(){
   if(promise != null && promise.$$state.status === 0)
      return;

   promise = doAsyncAnimation().then(function(){
       console.log('hey, i'm done!');
   });
}

这被认为是一种不好的做法?它会完全满足我的需要,而且我不喜欢使用单独的布尔变量来完成工作。 它有多少资格?

$$ 名称前缀指定内部使用的私有 property/service,如有更改,恕不另行通知。

来自the manual

Angular Prefixes $ and $$: To prevent accidental name collisions with your code, Angular prefixes names of public objects with $ and names of private objects with $$. Please do not use the $ or $$ prefix in your code

$q 不太可能对 $$state 进行重大更改。但是,它的用法表明未正确使用 promise。

在这种情况下,它只是

$scope.click = function(){
   if (promise)
      return;

   promise = doAsyncAnimation().then(function(){
       console.log('hey, i\'m done!');
   })
   .finally(function () {
       promise = null;
   });
}