Link to home
Start Free TrialLog in
Avatar of alborach
alborach

asked on

Javascript function scope problem...

I have the following code of javascript to cal a function of a component. Th problem is that when I tried to access the public function through the call: GUI_MiniCalendar.component.test() or GUI_MiniCalendar.component.viewCalendar() the functions are executed in firefox without problems, but in google chrome, ie and opera the functions aren't executed at all. What I'm doing wrong?


Ext.onReady(function() {

 Ext.namespace('GUI_MiniCalendar');

 GUI_MiniCalendar.component = function() {

 /**
 * Private Methods
 */
 function viewCalendar(month,year,evt)
 {
    alert('view calendar');
 }

 /**
 * Public methods
 */
 return {

  viewCalendar: function(month, year, evt)
  {
    viewCalendar(month, year, evt);
  },

  test: function()
  {
    alert('testing!');
  }

 }; // return

}();

 GUI_MiniCalendar.component.test();

});

Open in new window

ASKER CERTIFIED SOLUTION
Avatar of alborach
alborach

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of David S.
Yeah, it's best to avoid using JavaScript Reserved Keywords (https://developer.mozilla.org/en/Core_JavaScript_1.5_Reference/Reserved_Words ) as variable names, they may work in some cases in some browsers, but are very likely to break in others.
To that end:


/*

JavaScript Reserved Words
=========================
JavaScript is very heavy-handed in its restrictions on reserved words.

The reserved words are:

abstract
boolean 	break 		byte
case 		catch 		char 		class 		const 		continue
debugger 	default 	delete 		do 		double
else 		enum 		export 		extends
false 		final 		finally		float 		for 		function
goto
if 		implements 	import 		in 		instanceof 	int 		interface
long
native 		new 		null
package 	private 	protected 	public
return
short 		static 		super 		switch 		synchronized
this 		throw 		throws 		transient 	true 		try 		typeof
var		volatile	void
while		with

*/

Open in new window

Avatar of alborach
alborach

ASKER

thank you both for your comments!
No worries - glad to help.