簡體   English   中英

如何從私有訪問模塊上的公共方法?

[英]How can I access the public methods on a module from a private?

我有這個非常煩人的問題。 我需要能夠從私有模塊模式中訪問公共模塊功能。 我在有問題的線路上寫了一條評論...有什么辦法可以做到這一點?

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設計模式》這本書后,我意識到您做不到。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM