PDA

View Full Version : what's the difference of function functionName() and functionName:function()



iolerp
10 Aug 2007, 2:50 AM
who can tell me about the topic,and when I use "toolbar.add(el,{handler:functionName})",if I wrote the function like this:"function functionName()",it's ok! But when I use other expression:"functionName:function()",it will give me some error!
3q for your help!

BernardChhun
10 Aug 2007, 3:02 AM
when you use the ":", it's because it's inside a dictionnary. the function will be a part of an object.


var foo = function(){
function foobar(){
// private function inside the foo object
}
return {
bar : function(){
// a public function that you may call using "foo.bar()"
}
}
}();

you see how the foo object returns a dictionnary? that is used so that we can declare public and private functions.

read more on the matter here: http://www.permadi.com/tutorial/jsFunc/
and also look for Jozef's scope post here: http://extjs.com/forum/showthread.php?t=6336