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

Path csiph.com!v102.xanadu-bbs.net!xanadu-bbs.net!feeder.erje.net!eu.feeder.erje.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: call function for times with different types
Supersedes <6837367.xtaXS9kyqB@PointedEars.de>
Date Tue, 26 Aug 2014 14:56:18 +0200
Organization PointedEars Software (PES)
Lines 63
Message-ID <1813962.Ik3O7db6aP@PointedEars.de> (permalink)
References <1c60d2a4-3634-4cae-ad31-dc2d38cc911c@googlegroups.com>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1409057788 28546 eJwNycERACEIA8CWREiOlAM69F/COftcOI3nC4KBeVhaG7UV0ePsVrN1o5YSYX5PvpOwZ9L8BwzJEFY= (26 Aug 2014 12:56:28 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Tue, 26 Aug 2014 12:56:28 +0000 (UTC)
User-Agent KNode/4.13.3
Cancel-Key sha1:qtTRQRq1/wSl9UzFvIhuOXoErtI=
X-User-ID eJwNyMEBgEAIA7CVRGgL48gJ+4+geQZO41EQDCy2bDcn37wbJwr8CznjEEPcKWj7StNInm3Acxr5xtZx8QNJNRUb
Cancel-Lock sha1:UzzgsXDeI7eiu9XpGv+nnW4os4U=
X-NNTP-Posting-Host eJwFwQcBwEAIBDBLjGO8HEbxL6GJqbNPwM1hZzdCexJNBI1PO7FCSFkWhpLfw8yEvKrqJPsBCtcQhg==
Xref csiph.com comp.lang.javascript:25732

Show key headers only | 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