【问题标题】:How can I access the public methods on a module from a private?如何从私有访问模块上的公共方法?
【发布时间】:2014-08-19 16:09:19
【问题描述】:

我有这个非常烦人的问题。我需要能够从私有模块模式中访问公共模块功能。我已经对有问题的行写了评论...有什么办法吗?

angular.module("myApp").factory('models', [function () {

    function itemModel(dtoItem) {

        this.type = dtoItem.type;

    }

    function groupModel(dto) {

        this.items = [];

        angular.forEach(dto.getFeatures(), function (item) {
            self.items.push(new itemModel(item)); //THIS NEEDS TO BE self.items.push(new ItemModel(item)); (Notice the use of the capital letter to denote a public function) so that I can run a test externally and check the type of the 'items'
        });

    }

    return {
        ItemModel: itemModel,
        GroupModel: groupModel
    }

}]);

【问题讨论】:

    标签: javascript angularjs jasmine revealing-module-pattern


    【解决方案1】:

    读完Learning JavaScript Design Patterns这本书后,我意识到你做不到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-02-11
      • 1970-01-01
      • 1970-01-01
      • 2013-10-08
      • 2013-08-03
      • 1970-01-01
      • 1970-01-01
      • 2014-06-06
      相关资源
      最近更新 更多