Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #25732

Re: call function for times with different types

From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: call function for times with different types
Date 2014-08-26 14:56 +0200
Organization PointedEars Software (PES)
Message-ID <1813962.Ik3O7db6aP@PointedEars.de> (permalink)
References <1c60d2a4-3634-4cae-ad31-dc2d38cc911c@googlegroups.com>

Show all headers | View raw


吳晞浩 wrote:

> Hi, I was wondering in most of JavaScript programs. Is there any practical
> usage to call a function many times and each time with different types?

Yes, but you need to be careful with such overloading (many people, library 
authors included, are not).  It is usually important that you are able to 
tell different types of arguments apart in order to handle them differently; 
this excludes, for example, overloading with references to host objects.  
Also, a one-size-fits-all function quickly becomes hard to maintain.  So be 
slow to do that.

> Such kind of programs look awkward but it somehow follows the grammar

It follows the respective ECMAScript grammar exactly or it would not 
execute.  For ECMAScript Ed. 5.1, the relevant productions are

  CallExpression : MemberExpression Arguments

  Arguments : ( ArgumentList )

  ArgumentList :
    ArgumentList , AssignmentExpression
    ArgumentList : AssignmentExpression 

As you can see, there is no limitation as to what can be passed to a 
function except that the argument needs to be produced by 
AssignmentExpression.

> and JavaScript is a dynamic typed language.

The correct term here is “dynamic type-checking” (not: “weak typing”, which 
is underdefined).  The type of a symbol, like a variable or property, is 
checked when it is accessed, and implicit conversion is being done if 
necessary for an operation.

Whether that term applies to JavaScript depends on what you mean by 
“JavaScript”.  Contrary to popular belief, there is no single programming 
language to fit them all.  There are several implementations of Editions of 
ECMAScript which are different from one another (as allowed by the 
“Conformance” section of the Specification).  For example, there are 
implementations that may bear the “JavaScript” name but also support static 
type-checking (and other data types).  There you can declare the type for a 
formal parameter:

  function f (arg1 : int, arg2 : boolean)
  {
  }

However, those are, at least up to now, not used in an HTML context.

See the ES Matrix (URI below) for details.


Google Groups is borken with regard to Network News/Usenet.  You should use 
it only for searching newsgroups, not for posting to them.  Use a newsreader 
instead, like KNode, Thunderbird, or SeaMonkey Mail/News.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread


Thread

call function for times with different types 吳晞浩 <shwu.cs98@gmail.com> - 2014-08-25 22:59 -0700
  Re: call function for times with different types "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-08-26 09:22 +0200
    Re: call function for times with different types "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-26 09:44 +0200
      Re: call function for times with different types "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-08-26 10:11 +0200
        Re: call function for times with different types "Christoph M. Becker" <cmbecker69@arcor.de> - 2014-08-26 13:25 +0200
          Re: call function for times with different types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-26 17:25 +0200
            [OT] Chinese given names (was: call function for times with different types) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-27 01:40 +0200
          Re: call function for times with different types Denis McMahon <denismfmcmahon@gmail.com> - 2014-08-26 15:47 +0000
            [OT] Internet standards (was: call function for times with different types) Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-26 18:22 +0200
  Re: call function for times with different types Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-08-26 14:56 +0200
  Re: call function for times with different types Scott Sauyet <scott.sauyet@gmail.com> - 2014-09-02 13:39 -0700

csiph-web