Im trying to make my first jquery plugin.. but actually i dont know what im doing wrong here.
$(document.ready(function()
{
var plugin = (function()
{
//this function is not accessible from the outside
function privateFunction()
{
}
//these functions are
return
{
alert1: function()
{
alert('Hallo');
},
alert2: function()
{
alert("hi");
}
}
})()
//but it is not working :/
plugin.alert1();
});
it is not executing one of the alerts. Am i putting some semicolons wrong? i checked if all were closed
Javascript's automatic semicolon insertion will add a semicolon after return
and undefined
is returned.
Your code will look like
return;
{...
Replace
return
{
Should be
return {
You're also missing the )
after document
in the first line of code.
Demo
$(document).ready(function() { var plugin = (function() { //this function is not accessible from the outside function privateFunction() { // Code Here } //these functions are return { alert1: function() { alert('Hallo'); }, alert2: function() { alert("hi"); } }; }()); //but it is not working :/ plugin.alert1(); });
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.