melting_dog Posted May 26, 2012 Share Posted May 26, 2012 Hi all, I have been following a few JavaScript and JQuery tutorials and they always seem to use something called init. But they never explain it properly. EG: init: function(config) { $.extend(this.config, config); $('<button></button>', { text: 'Contact Me' }) OR: contactForm.init({ effect: 'fadeToggle', speed: 500 }); Couldnt find any info on the net either. Was wondering if someone could explain it to me? I no it standards for initialise but thats about it Thanks! Quote Link to comment https://forums.phpfreaks.com/topic/263150-newb-question-init/ Share on other sites More sharing options...
.josh Posted May 26, 2012 Share Posted May 26, 2012 A lot of times a script will have a "config" or "settings" variabe/object, or also a callback function that the script first calls or looks at when it runs, etc.. it's arbitrary, which is why you need to read the instructions that come with the script. For instance, if you have an image rotation script and the script works by updating an image tag with a new image src url, the script may allow you to specify the id attribute of the image tag and a list of URLs to rotate through, so it knows what image tag on the page to target and what images to display. init itself is not a special function. It is an arbitrarily named regular every day function just like any other javascript function. People just commonly use init as a naming convention specifically, because it is short, descriptive and intuitive in purpose. Quote Link to comment https://forums.phpfreaks.com/topic/263150-newb-question-init/#findComment-1348709 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.