简体   繁体   English

如何从私有访问模块上的公共方法?

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

I have this really annoying problem. 我有这个非常烦人的问题。 I need to able to access the public module function from within a private module pattern. 我需要能够从私有模块模式中访问公共模块功能。 I have written a comment on the problematic line...is there any way to do this? 我在有问题的线路上写了一条评论...有什么办法可以做到这一点?

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.

相关问题 如何从JavaScript模块中的私有和公共函数访问公共财产? - How to access public property from private and public functions in a JavaScript module? 在使用javascript模块模式时,如何从私有方法中调用公共方法? - How can i call a public method from within a private one when using the javascript Module Pattern? 从事件处理程序闭包访问公共和私有方法 - Access to public and private methods from event handler closure 单例访问私有方法访问公共方法 - Singleton Access Private methods acces public methods 具有私有/公共方法的Javascript模块模式 - Javascript Module pattern with private/public methods 具有私有/公共方法的高效Javascript模块模式 - Efficient Javascript Module pattern with private/public methods 如何在JavaScript模块模式中的私有函数中调用公共函数 - How do I call a public function from within a private function in the JavaScript Module Pattern 我可以在该模块的第二个定义中访问Marionette模块的私有变量吗? - Can I access a private variable of a Marionette module in a second definition of that module? 我如何测试IIFE的“私人”方法? - How can i test “private” methods of an IIFE? 如何在Javascript类中从“私有方法”访问“公共变量” - How to access from 'private method' to 'public variable', in Javascript class
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM