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 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> References: <1c60d2a4-3634-4cae-ad31-dc2d38cc911c@googlegroups.com> Reply-To: Thomas 'PointedEars' Lahn 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 吳晞浩 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: | SVN: Twitter: @PointedEars2 | ES Matrix: Please do not Cc: me. / Bitte keine Kopien per E-Mail.