• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 335
  • Last Modified:

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

0
alborach
Asked:
alborach
  • 2
  • 2
1 Solution
 
alborachAuthor Commented:
What turned out to be wrong is the name of a parameter I was sending in the request. The parameter was called 'function' and for some reason firefox make the request without problems, but opera and chrome failed to do so. Changing the name resolved the issue.
0
 
David S.Commented:
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.
0
 
BadotzCommented:
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

0
 
alborachAuthor Commented:
thank you both for your comments!
0
 
BadotzCommented:
No worries - glad to help.
0

Featured Post

Hire Technology Freelancers with Gigs

Work with freelancers specializing in everything from database administration to programming, who have proven themselves as experts in their field. Hire the best, collaborate easily, pay securely, and get projects done right.

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now