2016-08-18 12 views
0

なぜ(にconsole.log出力に基づいて)この作業決意匿名関数対javascriptの約束の解決機能

return new Promise(function(resolve) { 
    var test = function() { 
     console.log('rrrr'); 
     return $timeout(function(){},100); 
    } 
    resolve(test()); 
} 

があるしかし、これはないですか?

return new Promise(function(resolve) { 
    resolve(function() { 
     console.log('rrrr'); 
     return $timeout(function(){},100); 
    }); 
} 
+1

が、これは単なる例示のためですか?いずれのスニペットも本当に意味をなさないからです。 –

+0

'$ timeout'は何を返しますか? –

+0

@torazaburoそれはPromiseを返す – Gerard

答えて

1

テスト関数を呼び出しますが、下の1しか匿名関数を定義しトップ1ので。

はこれを試してみてください、それが動作するはずです:

return new Promise(function(resolve) { 
    resolve(function() { 
     console.log('rrrr'); 
     return $timeout(function(){},100); 
    }()); // the extra() will call your anonymous function. 
} 
+0

はい、優秀です。ありがとう! – Gerard

関連する問題