(function(){
var a = function () {
alert("hey now!! ");
};
return {"hi":function(){return a;}};
})();
hi();
This code doesn’ t work. How do i expose a function??
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
The self invoking function returns an object with the property
hi, this object is not added to the global scope so that you can use the property directly. Put the result of the function in a variable:Using the property to call the function will only return the function contained in the variable
a, so you have to call the return value from the function to call the function that contains the alert:Demo: http://jsfiddle.net/Guffa/9twaH/