Zuned Ahmed
Zuned Ahmed

Reputation: 1387

Kindly Help me out the javascript code

$(document).ready(function()
                {
                    IncomeDetails.initIncomeForm();
                });

The above code is written in XSL File.

Can anybody explain me what does this Javascript code means ? Is IncomeDetail is class ? what is it scope ? what is its use?

I find in my code this code is definded app.js file as

IncomeDetails = {

initIncomeForm : function()
{...some code here

what does it means?

Upvotes: 0

Views: 60

Answers (2)

aliz_bazar
aliz_bazar

Reputation: 292

The code means that once the DOM is ready, method initIncomeForm() of object IncomeDetails is executed. The code you're presenting is formed using Singleton pattern . It is an easy way for defining objects with multiple public and also private variables and methods.

The scope of a method is defined by the place in the code the method is defined. So in your case the scope of IncomeDetails object's methods is the surroundings of IncomeDetails object definition, in app.js.

In your case initIncomeForm does some initialization to the object. Probably it returns you another singleton object with methods and variables to access, but that is just a guess and can't be read from your code.

IncomeDetails is not a class in the strictest definition, but certainly acts as such. I suggest you to take a look at the article linked above, it explains different javascript patterns quite well.

Upvotes: 0

Adam Rackis
Adam Rackis

Reputation: 83366

IncomeDetails is an object and initIncomeForm is a method therein.

This syntax

IncomeDetails = {
   initIncomeForm : function() {

is how you declare an object literal in JavaScript, though the author may have been a bit sloppy. Assuming IncomeDetails is not previously declared elsewhere, leaving off the var here will cause this object to an implicit global variable, and therefore, to answer your other question, global in scope.

Upvotes: 2

Related Questions