PDA

View Full Version : need a code decifered


Crash1hd
04-20-2003, 07:07 AM
I was given a code by someone that does what I was looking for earlier! Yet all I was given was the js file so I was wondering if someone wouldnt mind taking a couple of minutes to decifer the following code for me exspecially the "init : function" and how that works as all functions I use are function init() so what programming or codeing is the stuff in red!

var MenuEvents = {
init : function() {
var t = document.getElementById("menu");
var handle = t.getElementsByTagName("H2").item(0);
MenuEvents.isOut = false;
handle.onclick = MenuEvents.clicked;
},

clicked : function(e) {
if(this.anim)
this.anim.cancelSlide();
if(!MenuEvents.isOut) {
this.anim = new Animation.obj( document.getElementById("menu") );
this.anim.slideTo(null, 30, 300);
MenuEvents.isOut = true;
} else {
this.anim = new Animation.obj( document.getElementById("menu") );
this.anim.slideTo(null, -270, 300);
MenuEvents.isOut = false;
}
}
}

the rest of the js file is attached! as a txt file

eggman
04-20-2003, 03:51 PM
Objects can be defined literally in Javascript.

var newObject=
{
aMethod:function(){alert("hi")},
aProperty:0
}

is equivalent to:

var newObject= new Object()
newObject.aMethod=function(){alert("hi")}
newObject.aProperty=0