Forum Moderators: open
var o = $('#form_area_'+ zid);
That's declaring a variable 'o' and assigning it the value of whatever is returned by the $() method. I believe the Prototype.js library has a $() method which is used to get an element by it's id. For example, if you have in your document something that has:
id="form_area_1"
Then if zid == 1, the above code would return a reference to that node and it would be assigned to o.
function EatCookies() { };
That created a function EatCookes that does nothing. Based on how this is being used, a better method would be to do this, since it doesn't look like it's really being used as a function:
var EatCookies = {};
EatCookies.lasttime = false;
That is assigning a value of false to a property "lasttime" of EatCookies.
EatCookies.data =
{
aid: null,
bid: null,
sometext: ''
};
The {} is used to create "object literals". An object literal contains key/value pairs. The above example creates an object and assigns it to the data property of the EatCookies object. This new object has 3 properties (aid, bid, and sometext). You can access those properties by doing:
EatCookies.data.aid = "foo";
EatCookies.data.bid = "bar";
alert( EatCookies.data.aid + " " + EatCookies.data.bid );
Note, the values of those properties can contain strings, arrays, boolean values, other objects, etc. Which means you could do something like this:
EatCookies.data.aid = [10,25,80]; // an array
EatCookies.data.aid = true; // a boolean
EatCookies.data.aid = {fname:"John",lname:"Smith"}; // an object
var o = $.....
I believe there is a function called $ which returns a list of object references based on it's parameters.
It's basically a lot of getElementById statements and returns an array. In this case it will find the element called '#form_area_'+ zid.
function EatCookies() { };
Is a function that does nothing. The next couple of lines set custom properties of the function (lasttime and data), looks like it's being set up for later use.
I was looking around on the web and it makes more sense now (after your explanation also!).
So I learned that: When we declare a function, javascript actually creates an object in the background that is the same name as the function.
[edited by: AffiliateDreamer at 11:09 pm (utc) on April 10, 2007]