473,406 Members | 2,710 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,406 software developers and data experts.

2 same function name ..

can i have 2 function with same function name but different argument in a javascript?

my code are as followings:-

Expand|Select|Wrap|Line Numbers
  1.     function crtHidObj(name,value,idx){
  2.         crtHidObj(name,value);
  3.         createCookie("CollectionRuleCrit."+name,value,100);
  4.         }
  5.  
  6.     function crtHidObj(name,value){
  7.         f=document.frmC5W002;
  8.         var hidObj = document.createElement("INPUT");
  9.         hidObj.setAttribute("type","hidden");
  10.         hidObj.setAttribute("name",name);
  11.         hidObj.setAttribute("value",value);
  12.         f.appendChild(hidObj);
  13.     }

Anyone know? pls reply ... many thanks !!~
Jan 28 '08 #1
3 2394
gits
5,390 Expert Mod 4TB
nope ... that will not work (the second one overwrites the first one) ... why should the functions have the same name?

kind regards
Jan 28 '08 #2
IE will default take the second one. just using different name will do
Jan 15 '17 #3
gits
5,390 Expert Mod 4TB
well - it doesn't have anything to do with a browser or its version. declaring a variable or a function with the same name overwrites the previous one. to give a clear answer i assume that the purpose of the original question was to define a function that can have optional arguments which could be solved for example like this:

Expand|Select|Wrap|Line Numbers
  1. function foo(arg1, arg2, arg3) {
  2.     if (typeof arg3 == 'undefined') {
  3.         // code that only requires arg1 and arg2
  4.     } else {
  5.         // code that requires arg3 
  6.     }
  7. }
  8.  
  9. // now method foo may be called as:
  10.  
  11. foo(1, 2);
  12.  
  13. // or:
  14.  
  15. foo(1, 2, 3);
Mar 15 '17 #4

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

Similar topics

8
by: Nick Coghlan | last post by:
Time for another random syntax idea. . . So, I was tinkering in the interactive interpreter, and came up with the following one-size-fits-most default argument hack: Py> x = 1 Py> def...
6
by: marcelf3 | last post by:
Hello.. This page opens a window with some information, but everytime the user changes a field in the parent window, the child window needs to be closed. These 2 functions were supposed to do the...
12
by: Susan Cranford | last post by:
Please forgive, I have looked at so much info I can't figure out how to put it together even though I know it must be fairly simple. I have an array of input text boxes (txtDOBn) where n is...
6
by: Bill Rubin | last post by:
The following code snippet shows that VC++ 7.1 correctly compiles a static member function invocation from an Unrelated class, since this static member function is public. I expected to compile the...
4
by: poojak | last post by:
I have write two different js function in a external file. one function write a table (I used innerHTML for this.) and another function is for showing/ hideing some rows depending on radio button...
2
by: ELINTPimp | last post by:
Hello all, Have a really interesting problem (at least to me) with my upload_file() function. I have it working now, with a bit of a work around, but would like to know what everyone thinks in...
6
by: Maguila007 | last post by:
Hi Is there any way to obtain the name of the function, inside the function which was called. Ex: function something() { alert( "The name of the function you invoke is " ......should
2
by: shivendravikramsingh | last post by:
hi friends, i m using a ajax function for retrieving some values from a database table,and display the values in required field,my prob is that the ajax function i m using is working f9 once,but if...
2
by: WGW | last post by:
Hello all, I need another set of eyes cause it just isn't working, no matter how identical I make it. The initRotator function works when called by itself, but when adding another function, only the...
5
by: mad.scientist.jr | last post by:
According to http://www.quirksmode.org/js/forms.html you need to look through a radio button's members to find the value: I tried writing a reusable function to return the value, see code at:...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
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,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

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.