Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #25726 > unrolled thread
| Started by | 吳晞浩 <shwu.cs98@gmail.com> |
|---|---|
| First post | 2014-08-25 22:59 -0700 |
| Last post | 2014-09-02 13:39 -0700 |
| Articles | 11 — 6 participants |
Back to article view | Back to comp.lang.javascript
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
| From | 吳晞浩 <shwu.cs98@gmail.com> |
|---|---|
| Date | 2014-08-25 22:59 -0700 |
| Subject | call function for times with different types |
| Message-ID | <1c60d2a4-3634-4cae-ad31-dc2d38cc911c@googlegroups.com> |
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? Such kind of programs look awkward but it somehow follows the grammar and JavaScript is a dynamic typed language.
A simple example would be:
function foo(a) {
//do something here
}
foo(10); //numeric types
foo("test") //string type
foo(false); //boolean type
foo({"a":1}); //object type
Thanks.
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-08-26 09:22 +0200 |
| Message-ID | <XnsA3955F56E2C50eejj99@194.109.133.133> |
| In reply to | #25726 |
=?UTF-8?B?5ZCz5pme5rWp?= <shwu.cs98@gmail.com> wrote on 26 aug 2014 in
comp.lang.javascript:
> Hi, I was wondering in most of JavaScript programs.
I do not believe you have even seen a tiny fraction of Javascript
programme scripts.
> Is there any
> practical usage to call a function many times and each time with
> different types?
Ues, there is, because the programmer choose to make the function behave
that way.
> Such kind of programs look awkward
Those are not a "kind of programme" but just the whim of the programmer,
who likes a general function to behave slightly differently based on the
parameter input, in stead of trying to remember a lot of different
functions. This definitey may have its merits.
> but it somehow
> follows the grammar and JavaScript is a dynamic typed language.
No, not as a dynamic typed language and it does not "follow the grammar".
Javascript just makes this possible as a *weak* typed language.
<http://en.wikipedia.org/wiki/Strong_and_weak_typing>
> A simple example would be:
>
> function foo(a) {
> //do something here
>}
The a parameter is not even necessary,
as all functions have an internal parameter collection:
function myFunction() {
for(var i=0; i<arguments.length; i++)
alert('Good morning, ' + arguments[i]);
};
Also in this example the parameter types can differ:
myFunction(23, 'Mr. Jones', employee(77), true)
[..]
> Thanks.
Could you please ad a signature or at least a nickname,
discussing with a nobody who seems to be named
=?UTF-8?B?5ZCz5pme5rWp?= is rather combersome
and we would, be it slowly, come to know
whether you are a strong or weak type of programmer.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-08-26 09:44 +0200 |
| Message-ID | <lthdt4$lhg$1@solani.org> |
| In reply to | #25727 |
schrieb Evertjan. wrote: > =?UTF-8?B?5ZCz5pme5rWp?= <shwu.cs98@gmail.com> wrote on 26 aug 2014 in > comp.lang.javascript: > > Could you please ad a signature or at least a nickname, > discussing with a nobody who seems to be named > =?UTF-8?B?5ZCz5pme5rWp?= is rather combersome > and we would, be it slowly, come to know > whether you are a strong or weak type of programmer. It seems your newsreader can't properly handle encoded-words[1]. The OP has posted as 吳晞浩 <shwu.cs98@gmail.com>, which is perfectly fine. [1] <http://tools.ietf.org/html/rfc2047> -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2014-08-26 10:11 +0200 |
| Message-ID | <XnsA39567ABAFC29eejj99@194.109.133.133> |
| In reply to | #25728 |
"Christoph M. Becker" <cmbecker69@arcor.de> wrote on 26 aug 2014 in comp.lang.javascript: > schrieb Evertjan. wrote: > >> =?UTF-8?B?5ZCz5pme5rWp?= <shwu.cs98@gmail.com> wrote on 26 aug 2014 in >> comp.lang.javascript: >> >> Could you please ad a signature or at least a nickname, >> discussing with a nobody who seems to be named >> =?UTF-8?B?5ZCz5pme5rWp?= is rather combersome >> and we would, be it slowly, come to know >> whether you are a strong or weak type of programmer. > > It seems your newsreader can't properly handle encoded-words[1]. The OP > has posted as 蜷ウ譎樊オゥ <shwu.cs98@gmail.com>, which is perfectly fine. I don't think ウ譎樊オゥ is perfectly fine, usenet stipulates using ASCII for addresslines, so much for your "properly". However, dear Christoph, even having a fine addressline, quod non, does not in the least diminish the value of my request for a signature or at least a nickname. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Date | 2014-08-26 13:25 +0200 |
| Message-ID | <lthqqe$7gd$1@solani.org> |
| In reply to | #25729 |
Evertjan. wrote: > "Christoph M. Becker" <cmbecker69@arcor.de> wrote on 26 aug 2014 in > comp.lang.javascript: > >> schrieb Evertjan. wrote: >> >>> =?UTF-8?B?5ZCz5pme5rWp?= <shwu.cs98@gmail.com> wrote on 26 aug 2014 in >>> comp.lang.javascript: >>> >>> Could you please ad a signature or at least a nickname, >>> discussing with a nobody who seems to be named >>> =?UTF-8?B?5ZCz5pme5rWp?= is rather combersome >>> and we would, be it slowly, come to know >>> whether you are a strong or weak type of programmer. >> >> It seems your newsreader can't properly handle encoded-words[1]. The OP >> has posted as å³ææµ© <shwu.cs98@gmail.com>, which is perfectly fine. > > I don't think ³ææµ© is perfectly fine, usenet stipulates using ASCII for > addresslines, so much for your "properly". It seems you are referring to RFC 1036 section 2.1.1. However, RFC 1036 is obsoleted by RFC 5536 and 5537, and RFC 5536 section 3.1.2 specifies: | The From header field is the same as that specified in Section 3.6.2 | of [RFC5322], with the added restrictions detailed above in | Section 2.2. I have not been able to find any restriction on ASCII characters, besides that non ASCII characters have to be encoded, what they have been in the OP. However, if you post to Usenet, you should be aware that the default Content-Type is Content-type: text/plain; charset=us-ascii So if you are using non ASCII characters, you should configure your newsreader to add an appropriate Content-Type header field. > However, dear Christoph, even having a fine addressline, quod non, does not > in the least diminish the value of my request for a signature or at least a > nickname. Well, the name has been already given in the "addressline"--there is no *need* to duplicate it. -- Christoph M. Becker
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-08-26 17:25 +0200 |
| Message-ID | <1599457.KEItprr6EY@PointedEars.de> |
| In reply to | #25730 |
Christoph M. Becker wrote:
> Evertjan. wrote:
>> "Christoph M. Becker" […] wrote […]:
> However, if you post to Usenet, you should be aware that the default
> Content-Type is
>
> Content-type: text/plain; charset=us-ascii
>
> So if you are using non ASCII characters, you should configure your
^ in the message *body*
> newsreader to add an appropriate Content-Type header field.
JFTR: The “Content-Type” header field only applies to the message body.
>> However, dear Christoph, even having a fine addressline, quod non, does
>> not in the least diminish the value of my request for a signature or at
>> least a nickname.
>
> Well, the name has been already given in the "addressline"--there is no
> *need* to duplicate it.
However, since English, not Chinese, has become the /lingua franca/ of
computer science (and technology in general), it is be prudent to specify
the Hanyu Pinyin transcription of the name as well (or instead of the real
name) in this international newsgroup. In this case, with Google Translate
recognizing the name as Chinese, it would probably be “Wu Xi Hao” (as
suggested there). “Wu” being a common Chinese family name, it would be
customary to write “WU Xi Hao” to signify that.
I know first-hand from my flatmates at the university back in 2003 that at
least some Chinese like to choose an English first name on the Net instead
of their real first name which might be difficult to pronounce properly, and
even more difficult to write, by people whose native language is not one of
the Chinese languages. The traditional order of the given name is then
reversed, for example “Robert Wu” (which, by serendipity, is also the name
of a Chinese-American actor and producer).
--
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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-08-27 01:40 +0200 |
| Subject | [OT] Chinese given names (was: call function for times with different types) |
| Message-ID | <1539570.9XgXjDoHMo@PointedEars.de> |
| In reply to | #25733 |
Thomas 'PointedEars' Lahn wrote: > However, since English, not Chinese, has become the /lingua franca/ of > computer science (and technology in general), it is be prudent to specify > the Hanyu Pinyin transcription of the name as well (or instead of the real > name) in this international newsgroup. In this case, with Google > Translate recognizing the name as Chinese, it would probably be “Wu Xi > Hao” (as suggested there). “Wu” being a common Chinese family name, it > would be customary to write “WU Xi Hao” to signify that. I have just learned that although there are three characters (吳晞浩), the pinyin romanization should not be written “Wu Xi Hao”, but (without tone marks) probably “Wu Xihao” or “Wu Xiao”. Another possibility is the older Wade-Giles system, in which it could be (without tone marks) „Wu Xi-Hao“. <https://en.wikipedia.org/wiki/Chinese_given_name#Description> F'up2 alt.chinese.text -- 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.
[toc] | [prev] | [next] | [standalone]
| From | Denis McMahon <denismfmcmahon@gmail.com> |
|---|---|
| Date | 2014-08-26 15:47 +0000 |
| Message-ID | <ltia64$omd$1@dont-email.me> |
| In reply to | #25730 |
On Tue, 26 Aug 2014 13:25:05 +0200, Christoph M. Becker wrote: > It seems you are referring to RFC 1036 section 2.1.1. However, RFC 1036 > is obsoleted by RFC 5536 and 5537, and RFC 5536 section 3.1.2 specifies: I think you'll find that until RFCs 5536 and 5537 are actually standards, rather than 5 year old proposed standards, they don't obsolete 1036. -- Denis McMahon, denismfmcmahon@gmail.com
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-08-26 18:22 +0200 |
| Subject | [OT] Internet standards (was: call function for times with different types) |
| Message-ID | <2447277.PWrZg0qSN9@PointedEars.de> |
| In reply to | #25734 |
Denis McMahon wrote: > On Tue, 26 Aug 2014 13:25:05 +0200, Christoph M. Becker wrote: >> It seems you are referring to RFC 1036 section 2.1.1. However, RFC 1036 >> is obsoleted by RFC 5536 and 5537, and RFC 5536 section 3.1.2 specifies: > > I think you'll find that until RFCs 5536 and 5537 are actually standards, > rather than 5 year old proposed standards, they don't obsolete 1036. Your logic is flawed and your research method is lacking. You will find that RFCs 5536, 5537, and 5322 are *Proposed* Standards and a *Draft* Standard, respectively – RFCs on the IETF Standards Track (not Internet standards yet; those have an STD number, too) –, and that, regardless of that, the former two *explicitly* obsolete RFC 1036 and the latter obsoletes RFC 2822. As such, they bear the informal significance of “quasi-standard” or “de-facto standard” – something to be observed if one is to avoid interoperability problems. It was about time in 2009, with the so-called “Son-of-RFC-1036” working draft being the implemented de-facto standard for Network News for the previous 9 years at least (it was the de-facto standard when I first used Usenet). -- 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.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2014-08-26 14:56 +0200 |
| Message-ID | <1813962.Ik3O7db6aP@PointedEars.de> |
| In reply to | #25726 |
吳晞浩 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.
[toc] | [prev] | [next] | [standalone]
| From | Scott Sauyet <scott.sauyet@gmail.com> |
|---|---|
| Date | 2014-09-02 13:39 -0700 |
| Message-ID | <6c2407f6-07ba-4873-b711-0dff1f068e93@googlegroups.com> |
| In reply to | #25726 |
Jack 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? Such kind of programs look awkward but it somehow
> follows the grammar and JavaScript is a dynamic typed language.
Consider this:
var filterLessThan = function(val, list) {
return list.filter(function(item) {return item < val;});
};
filterLessThan("f", ["t", "b", "a", "s", "d", "g", "i", "w"]);
//=> ["b", "a", "d"]
filterLessThan(5, [8, 6, 7, 5, 3, 0, 9]);
//=> [3, 0]
This simple function accepts a signal value and a list and returns a
new list containing only those elements of the original list less than
that signal.
We could have written separate functions for strings and for numbers,
but the algorithm is identical. It is much clearer to my mind to use
the same function for both.
And of course there are many cases like this, involving many more
types than just strings and numbers.
That's one reason.
-- Scott
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web