Nilesh Nilesh - 1 year ago 69
Javascript Question

(function($) { ..})(jQuery); function defined in this wrapper/closure can not be called outside

I have following block ,where I have defined 1 function, I am trying to call that function outside block, it gives me function undefined error.why?

(function($) {
function addNumbers(num1, num2) {
return num1 + num2;


addNumbers(2,3) return error undefined function.

what can i do to make addNumbers() to call outside of this block?

Answer Source

It is a basic scoping issue. If you declare a function inside another function, it is only accessible inside that function. You can't access it outside.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download