473,387 Members | 1,592 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

getting function name with javascript, fails in IE.

Auz
2
Hello.

I have problem with getting the name of a function with javascript. The code I have works fine in firefox, but not in internet explorer. Its part of a much larger whole, but what it boils down to is this:

Expand|Select|Wrap|Line Numbers
  1. function dog() { alert('bark'); } 
  2. var myvar=dog; 
  3. alert(myvar.name); 
  4.  
Firefox returns 'dog', but ie does not. Is there any other way to do this?

thanks
-Auz
Jan 4 '07 #1
2 3162
b1randon
171 Expert 100+
Hello.

I have problem with getting the name of a function with javascript. The code I have works fine in firefox, but not in internet explorer. Its part of a much larger whole, but what it boils down to is this:

Expand|Select|Wrap|Line Numbers
  1. function dog() { alert('bark'); } 
  2. var myvar=dog; 
  3. alert(myvar.name); 
  4.  
Firefox returns 'dog', but ie does not. Is there any other way to do this?

thanks
-Auz
IE doesn't give functions a .name apparently. I used a simple regular expression to do this:
Expand|Select|Wrap|Line Numbers
  1. function dog() { 
  2.     alert('bark'); 
  3.  
  4. function fnName() {
  5.     var fn = myvar.toString();
  6.     var name = fn.split(/[\s\(]/g)
  7.     alert(name[1]); 
  8. }
  9.  
  10. var myvar=dog; 
  11. fnName();
  12.  
Also, here is a good regular expression reference.
Jan 4 '07 #2
Auz
2
Thanks very much, that works well.

-Auz
Jan 4 '07 #3

Sign in to post your reply or Sign up for a free account.

Similar topics

2
by: Eyal | last post by:
Hey, I would appriciate if anyone can help on this one: I have a java object/inteface having a method with a boolean parameter. As I'm trying to call this method from a javascript it fails on...
3
by: Fabian | last post by:
I have created a javascript to manipulate a text strong given to it. It works in all the situations I put it in. Now, I want to create a form based interface. Essentially, the use types in the text...
6
by: Martin | last post by:
I'd like to be able to get the name of an object instance from within a call to a method of that same object. Is this at all possible? The example below works by passing in the name of the object...
4
by: gimme_this_gimme_that | last post by:
Hi, This is sort of a : How to build a Yes/No dialog box qquestion. Or perhaps a question about getting javascript variables from a pop-up window and processing them on a submit. This is...
5
by: Jason | last post by:
I'm new to WebForms and struggling with very basic stuff at the moment. I am trying to figure out how to detect a radiobutten click state using JavaScript. The following OnCheckedChanged code...
4
by: roohbir | last post by:
Hello, I need help with the following code. Would be very grateful for comments. I have a function called emailValid, and it is supposed to alert the user if h/she leaves the field blank. I want...
1
by: simbarashe | last post by:
Hie could someone please help me with getting and using the current page url. I have a function that gets the url, I want to use it with header(location : XXX) but it wont work. The code is as...
7
by: gregp1 | last post by:
Hi guys, Here's the code I'm to refer to: <html> <body> .... <form method="get" action="http://www.google.com/search" name="google" />
1
by: raghuvendra | last post by:
Hi I have a jsp page with 4 columns: namely Category name , Category order, Input field and a submit button. All these are aligned in a row. And Each Category Name has its corresponding Category...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.