Jump to content

Newb Question: init?


melting_dog

Recommended Posts

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!

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.