相关疑难解决方法(0)

什么是明确的承诺构建反模式,我该如何避免它?

我编写的代码看起来像:

function getStuffDone(param) {           | function getStuffDone(param) {
    var d = Q.defer(); /* or $q.defer */ |     return new Promise(function(resolve, reject) {
    // or = new $.Deferred() etc.        |     // using a promise constructor
    myPromiseFn(param+1)                 |         myPromiseFn(param+1)
    .then(function(val) { /* or .done */ |         .then(function(val) {
        d.resolve(val);                  |             resolve(val);
    }).catch(function(err) { /* .fail */ |         }).catch(function(err) {
        d.reject(err);                   |             reject(err);
    });                                  |         });
    return d.promise; /* or promise() */ |     });
}                                        | }
Run Code Online (Sandbox Code Playgroud)

有人告诉我这个被称为" 延迟反模式 "或" Promise构造函数反模式 ",这个代码有什么不好,为什么这被称为 …

javascript promise q bluebird es6-promise

479
推荐指数
3
解决办法
7万
查看次数

AngularJS:工厂$ http.get JSON文件

我期待在本地开发只有一个硬编码的JSON文件.我的JSON文件如下(放入JSON验证器时有效):

{
    "contentItem": [
            {
            "contentID" : "1", 
            "contentVideo" : "file.mov",
            "contentThumbnail" : "url.jpg",
            "contentRating" : "5",
            "contentTitle" : "Guitar Lessons",
            "username" : "Username", 
            "realname" : "Real name",
            "contentTags" : [
                { "tag" : "Guitar"},
                { "tag" : "Intermediate"},
                { "tag" : "Chords"}
            ],      
            "contentAbout" : "Learn how to play guitar!",
            "contentTime" : [
                { "" : "", "" : "", "" : "", "" : ""},
                { "" : "", "" : "", "" : "", "" : ""} …
Run Code Online (Sandbox Code Playgroud)

json factory http angularjs

84
推荐指数
2
解决办法
34万
查看次数

标签 统计

angularjs ×1

bluebird ×1

es6-promise ×1

factory ×1

http ×1

javascript ×1

json ×1

promise ×1

q ×1