How to access "private functions" in one element from another object inside it

I'm currently trying to create a test suite for my javascript applications. My problem is that it seems that I cannot access init () from my utils object, as you can see below:

I have an application that follows a singleton pattern:

var appModal = function () {
    var utils = Object.create(moduleUtils);
     function init(caller, options ) {
    }
}();

My test suite is in the Utils module, this is an object literal converted to a prototype

moduleUtils.debug = {
    addSlideTest : function(){
        /* this function cannot fire init() from appModal */
}}
+3
source share
1 answer

It's impossible.
You need to open private functions in a public object.

, testMethods . , , :

//In appModal
if (typeof testMethods === "object")
    testMethods.init = init;

//In test suite
testMethods = { };
...
testMethods.init();
+1

Source: https://habr.com/ru/post/1744720/


All Articles