javascript - Help with JS and functions parameters -


Does JS support two functions with the same name and different parameters?

(a, b) {// A and B numbers are} function F1 (A, B, C) {// A is string / / b and c numbers}

Do I have any problems for IE7, FF, Opera?

Javascript does not help you will call method overloading in other languages, But there are more than one action, such as to use objects, to see how many arguments have been applied to the function:

  function f1 (A, b, c) {if (Arguments.length == 2) {// f1 has been called with two arguments} and if (arguments.length == 3) {// f1 is called with three arguments}}  < / Pre> 

Additionally you can You can type the logic, the number and string primitives for the typeof operator is safe to use:

  function F1 (A, B, C) {If (typef A == 'number' & amp; amp; typeof b == 'number') {// a and b are numbers} otherwise (if type = A 'string' & amp; ; Amp; amp; type; b == 'number' & amp; amp; amp; amp; amp; amp; amp; amp; type; {// A is a string, b and c numbers}}  

and the following article contains very similar sophisticated techniques Closer to imitate the method overloading :

  • , which takes advantage of some JavaScript language features , Function app, etc.,

    Comments

    Popular posts from this blog

    sql - dynamically varied number of conditions in the 'where' statement using LINQ -

    asp.net mvc - Dynamically Generated Ajax.BeginForm -

    Debug on symbian -