0

This is common.js

jQuery(function ($) {

    var commonJs = {
        init: function () {
        },
        showAlert: function () {
        },

    }

});

This is add.js

jQuery(function ($) {

    var addJs = {
        init: function () {
            console.log(commonJs.showAlert);
        },
    }

});

I want to use common js function commonJs.showAlert in add.js

How can i access that?

2 Answers 2

-1

Please simply place commonJs var outside the jQuery function and try again. It will work for you.

1
  • Thank you. It worked Commented Mar 19, 2020 at 5:02
0
var commonJs;
jQuery(function ($) {

    commonJs = {
        init: function () {
        },
        showAlert: function () {
        },

    }

});

I just had to put this variable outside jQuery(function ($) and it worked.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.