Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #31520 > unrolled thread
| Started by | justaguy <lichunshen84@gmail.com> |
|---|---|
| First post | 2016-10-08 14:48 -0700 |
| Last post | 2016-10-10 17:05 -0700 |
| Articles | 20 — 6 participants |
Back to article view | Back to comp.lang.javascript
How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-08 14:48 -0700
Re: How to have multiple and undetermined number of arguments for function? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-10-09 00:07 +0200
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-08 16:03 -0700
Re: How to have multiple and undetermined number of arguments for function? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-10-09 09:59 +0200
Re: How to have multiple and undetermined number of arguments for function? John Harris <niam@jghnorth.org.uk.invalid> - 2016-10-09 15:35 +0100
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-09 11:22 -0700
Re: How to have multiple and undetermined number of arguments for function? Ben Bacarisse <ben.usenet@bsb.me.uk> - 2016-10-09 20:09 +0100
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-09 13:32 -0700
Re: How to have multiple and undetermined number of arguments for function? "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2016-10-09 23:26 +0200
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-09 15:18 -0700
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-10 07:57 -0700
Re: How to have multiple and undetermined number of arguments for function? Jake Jarvis <pig_in_shoes@yahoo.com> - 2016-10-10 17:26 +0200
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-10 08:50 -0700
Re: How to have multiple and undetermined number of arguments for function? Jake Jarvis <pig_in_shoes@yahoo.com> - 2016-10-10 18:53 +0200
Re: How to have multiple and undetermined number of arguments for function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-10 18:22 +0100
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-10 11:20 -0700
Re: How to have multiple and undetermined number of arguments for function? Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-10-10 17:28 +0100
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-09 11:20 -0700
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-09 12:10 -0700
Re: How to have multiple and undetermined number of arguments for function? justaguy <lichunshen84@gmail.com> - 2016-10-10 17:05 -0700
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-08 14:48 -0700 |
| Subject | How to have multiple and undetermined number of arguments for function? |
| Message-ID | <c8d1b70e-031e-4b10-a454-afee5d0c9590@googlegroups.com> |
Hi,
Could we create a generic function like the following?
Genf = function () {
// do stuff below
};
Then, call this function like
Genf (arg1)
Or
Genf (arg1,arg2)
...
And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
Thanks.
[toc] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2016-10-09 00:07 +0200 |
| Message-ID | <XnsA69C13F81E0Feejj99@194.109.6.166> |
| In reply to | #31520 |
justaguy <lichunshen84@gmail.com> wrote on 08 Oct 2016 in
comp.lang.javascript:
> Could we create a generic function like the following?
> Genf = function () {
> // do stuff below
>
>};
>
> Then, call this function like
> Genf (arg1)
> Or
> Genf (arg1,arg2)
> ...
>
> And if it'still doable, do we habe something like arguments.length? So
> that we an loop through for each argument.
<https://developer.mozilla.org/en/docs/Web/JavaScript/Reference/Functions/ar
guments>
Why would I have to look this up?
Can't you do it yourself?
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-08 16:03 -0700 |
| Message-ID | <f727ca46-db56-4bf4-9fdb-e45f801faee2@googlegroups.com> |
| In reply to | #31521 |
Ok, thanks for the point, thought so.
Now, I can do something like
If (typeof arguments) {
// get each argument now
For (counter=0; counter < arguments.length; counter++) {
arguments [counter];
// and pass each argument for further action
}
}
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2016-10-09 09:59 +0200 |
| Message-ID | <XnsA69C65AA254B5eejj99@194.109.6.166> |
| In reply to | #31522 |
justaguy <lichunshen84@gmail.com> wrote on 09 Oct 2016 in comp.lang.javascript: > Ok, thanks for the point, thought so. Please quote what you are responding on. -- Evertjan. The Netherlands. (Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | John Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2016-10-09 15:35 +0100 |
| Message-ID | <l4lkvb5qrrojvvt7h9f34g2b3rhp81pcki@4ax.com> |
| In reply to | #31520 |
On Sat, 8 Oct 2016 14:48:26 -0700 (PDT), justaguy
<lichunshen84@gmail.com> wrote:
>Hi,
>
>Could we create a generic function like the following?
>Genf = function () {
>// do stuff below
>
>};
>
>Then, call this function like
>Genf (arg1)
>Or
>Genf (arg1,arg2)
>...
>
>And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
Or you can supply one argument every time it's called : an array that
carries all the values the caller wants to have processed.
It's now obvious that the function processes a variable number of
values. These values can have been collected at different points in
the program.
If the values are to hand at the call point you have to type
f([a, b, c, d]) instead of f(a, b, c, d). Some people would
resent that.
John
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-09 11:22 -0700 |
| Message-ID | <9abdc041-3977-470c-a886-b6ae885818c8@googlegroups.com> |
| In reply to | #31539 |
I attempted with the idea of taking an array as one argument without success, for instance,
addSectionFunction([arg1,input,60],[arg2,input,15])
Not doable?
Thanks.
On Sunday, October 9, 2016 at 10:35:22 AM UTC-4, John Harris wrote:
> On Sat, 8 Oct 2016 14:48:26 -0700 (PDT), justaguy
> <lisdgmail.com> wrote:
>
> >Hi,
> >
> >Could we create a generic function like the following?
> >Genf = function () {
> >// do stuff below
> >
> >};
> >
> >Then, call this function like
> >Genf (arg1)
> >Or
> >Genf (arg1,arg2)
> >...
> >
> >And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
>
> Or you can supply one argument every time it's called : an array that
> carries all the values the caller wants to have processed.
>
> It's now obvious that the function processes a variable number of
> values. These values can have been collected at different points in
> the program.
>
> If the values are to hand at the call point you have to type
> f([a, b, c, d]) instead of f(a, b, c, d). Some people would
> resent that.
>
> John
[toc] | [prev] | [next] | [standalone]
| From | Ben Bacarisse <ben.usenet@bsb.me.uk> |
|---|---|
| Date | 2016-10-09 20:09 +0100 |
| Message-ID | <87oa2ttk3f.fsf@bsb.me.uk> |
| In reply to | #31541 |
justaguy <lichunshen84@gmail.com> writes: Please don't top post... > I attempted with the idea of taking an array as one argument without > success, for instance, > addSectionFunction([arg1,input,60],[arg2,input,15]) That's not "an array as one argument". That's two arrays and two arguments. > Not doable? All such argument schemes are possible: multiple non-array arguments, one single array argument, multiple arrays arguments, multiple arrays of arrays or arrays of arguments -- you name it. Did you read the MDN reference the was posted? Did it not give you basic mechanisms to do what you want? <snip> -- Ben.
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-09 13:32 -0700 |
| Message-ID | <441c0eb7-210d-4310-b58c-216a6a157dae@googlegroups.com> |
| In reply to | #31542 |
On Sunday, October 9, 2016 at 3:10:01 PM UTC-4, Ben Bacarisse wrote: > justaguy <lichgmail.com> writes: > > Please don't top post... > > > I attempted with the idea of taking an array as one argument without > > success, for instance, > > addSectionFunction([arg1,input,60],[arg2,input,15]) > > That's not "an array as one argument". That's two arrays and two > arguments. > > > Not doable? > > All such argument schemes are possible: multiple non-array arguments, > one single array argument, multiple arrays arguments, multiple arrays of > arrays or arrays of arguments -- you name it. > > Did you read the MDN reference the was posted? Did it not give you > basic mechanisms to do what you want? > > <snip> > -- > Ben. Sorry for miscommunication, I meant trying out if an array can be considered as an argument. I just experimented with "multiple arrays arguments", it seems to work, however, when one such array is of this value: ['dated','date',15] this array has been ignored. Host environment: recent version of Chrome on Windows 10. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2016-10-09 23:26 +0200 |
| Message-ID | <XnsA69CEE721F5C2eejj99@194.109.6.166> |
| In reply to | #31544 |
justaguy <lichunshen84@gmail.com> wrote on 09 okt 2016 in comp.lang.javascript: > I just experimented with "multiple arrays arguments", it seems to work, > however, when one such array is of this value: ['dated','date',15] this > array has been ignored. Host environment: recent version of Chrome on > Windows 10. I trust that is not true. What would youn mean by "ignored"?
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-09 15:18 -0700 |
| Message-ID | <7112eabe-6254-4ac4-b2f2-ff9d3d6cff5e@googlegroups.com> |
| In reply to | #31545 |
On Sunday, October 9, 2016 at 5:26:28 PM UTC-4, Evertjan. wrote: > justaggmail.com> wrote on 09 okt 2016 in > comp.lang.javascript: > > > I just experimented with "multiple arrays arguments", it seems to work, > > however, when one such array is of this value: ['dated','date',15] this > > array has been ignored. Host environment: recent version of Chrome on > > Windows 10. > > I trust that is not true. > > What would youn mean by "ignored"? Yes, you're right, my bad. Each such array needs to have 4 elements of data, for instance, ['dated','input','date',15] Thanks.
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-10 07:57 -0700 |
| Message-ID | <f50fbc4b-55b1-4e66-8745-e20fba0b54d8@googlegroups.com> |
| In reply to | #31546 |
A related question.
I have one array as an argument for my the function in question, such array reads as ['grantor_row2','input','text',70].
In my loop for arguments, I have the following code with the intention of excluding this array,
if (!arguments[counter][0].indexOf('_row2')) {
console.log(arguments[counter][0]);
}
But the console did not return the value of 'grantor_row2'. What's wrong?
Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
|---|---|
| Date | 2016-10-10 17:26 +0200 |
| Message-ID | <ntgbvb$5e0$1@dont-email.me> |
| In reply to | #31550 |
Am 10.10.2016 um 16:57 schrieb justaguy:
> A related question.
>
> I have one array as an argument for my the function in question, such array reads as ['grantor_row2','input','text',70].
>
> In my loop for arguments, I have the following code with the intention of excluding this array,
> if (!arguments[counter][0].indexOf('_row2')) {
> console.log(arguments[counter][0]);
> }
>
> But the console did not return the value of 'grantor_row2'. What's wrong?
>
> Thanks.
>
You are actually checking if the first element starts with "_row2".
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-10 08:50 -0700 |
| Message-ID | <718ec6b6-a194-48b3-87b9-3330b2f485d1@googlegroups.com> |
| In reply to | #31551 |
On Monday, October 10, 2016 at 11:26:57 AM UTC-4, Jake Jarvis wrote:
> Am 10.10.2016 um 16:57 schrieb justaguy:
> > A related question.
> >
> > I have one array as an argument for my the function in question, such array reads as ['grantor_row2','input','text',70].
> >
> > In my loop for arguments, I have the following code with the intention of excluding this array,
> > if (!arguments[counter][0].indexOf('_row2')) {
> > console.log(arguments[counter][0]);
> > }
> >
> > But the console did not return the value of 'grantor_row2'. What's wrong?
> >
> > Thanks.
> >
>
> You are actually checking if the first element starts with "_row2".
I see. Thought, indexOf is sort of "contains". In the meantime, I have another statement,
if (arguments[counter][0].indexOf('_row2')) {
// do this an that
}
and it found it. How come?
Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Jake Jarvis <pig_in_shoes@yahoo.com> |
|---|---|
| Date | 2016-10-10 18:53 +0200 |
| Message-ID | <ntgh20$p79$1@dont-email.me> |
| In reply to | #31552 |
Am 10.10.2016 um 17:50 schrieb justaguy:
> On Monday, October 10, 2016 at 11:26:57 AM UTC-4, Jake Jarvis wrote:
>> Am 10.10.2016 um 16:57 schrieb justaguy:
>>> A related question.
>>>
>>> I have one array as an argument for my the function in question, such array reads as ['grantor_row2','input','text',70].
>>>
>>> In my loop for arguments, I have the following code with the intention of excluding this array,
>>> if (!arguments[counter][0].indexOf('_row2')) {
>>> console.log(arguments[counter][0]);
>>> }
>>>
>>> But the console did not return the value of 'grantor_row2'. What's wrong?
>>>
>>> Thanks.
>>>
>>
>> You are actually checking if the first element starts with "_row2".
>
> I see. Thought, indexOf is sort of "contains". In the meantime, I have another statement,
> if (arguments[counter][0].indexOf('_row2')) {
> // do this an that
> }
> and it found it. How come?
>
> Thanks.
>
You need to look a bit closer, something is being done to the result of
indexOf.
The ! operator is applied to it.
indexOf just returns -1 or position inside the string
For what numbers that indexOf might return does ! give a true?
For a 0
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-10-10 18:22 +0100 |
| Message-ID | <9018847.nUPlyArG6x@PointedEars.de> |
| In reply to | #31554 |
Jake Jarvis wrote:
> Am 10.10.2016 um 17:50 schrieb justaguy:
>> […]
>> I see. Thought, indexOf is sort of "contains". In the meantime, I have
>> another statement, if (arguments[counter][0].indexOf('_row2')) {
>> // do this an that
>> }
>> and it found it. How come?
>
> You need to look a bit closer, something is being done to the result of
> indexOf.
> The ! operator is applied to it.
>
> indexOf just returns -1 or position inside the string
>
> For what numbers that indexOf might return does ! give a true?
> For a 0
(I stand) correct(ed). But now they have omitted the “!” operator,
reversing the condition, so the block will be executed whenever the element
either does not contain or does not start with "_row2".
IOW, the proper way to do this is
if (arguments[counter][0].indexOf("_row2") > -1)
{
/* do things if first element contains "_row2" */
}
or
if (arguments[counter][0].indexOf("_row2") >= 0)
{
/* do things if first element contains "_row2" */
}
if arguments[counter] is a reference to an array-like object.
--
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 | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-10 11:20 -0700 |
| Message-ID | <15aedc65-0530-4e51-b5f9-b4024e310d73@googlegroups.com> |
| In reply to | #31555 |
On Monday, October 10, 2016 at 1:22:35 PM UTC-4, Thomas 'PointedEars' Lahn wrote:
> Jake Jarvis wrote:
>
> > Am 10.10.2016 um 17:50 justaguy:
> >> […]
> >> I see. Thought, indexOf is sort of "contains". In the meantime, I have
> >> another statement, if (arguments[counter][0].indexOf('_row2')) {
> >> // do this an that
> >> }
> >> and it found it. How come?
> >
> > You need to look a bit closer, something is being done to the result of
> > indexOf.
> > The ! operator is applied to it.
> >
> > indexOf just returns -1 or position inside the string
> >
> > For what numbers that indexOf might return does ! give a true?
> > For a 0
>
> (I stand) correct(ed). But now they have omitted the “!” operator,
> reversing the condition, so the block will be executed whenever the element
> either does not contain or does not start with "_row2".
>
> IOW, the proper way to do this is
>
> if (arguments[counter][0].indexOf("_row2") > -1)
> {
> /* do things if first element contains "_row2" */
> }
>
> or
>
> if (arguments[counter][0].indexOf("_row2") >= 0)
> {
> /* do things if first element contains "_row2" */
> }
>
> if arguments[counter] is a reference to an array-like object.
>
You're exactly correct and that's how I revised it a few minutes after posting the question and it's working now for that part. Thanks.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2016-10-10 17:28 +0100 |
| Message-ID | <2541393.e9J7NaK4W3@PointedEars.de> |
| In reply to | #31551 |
Jake Jarvis wrote:
> Am 10.10.2016 um 16:57 schrieb justaguy:
>> I have one array as an argument for my the function in question, such
>> array reads as ['grantor_row2','input','text',70].
>>
>> In my loop for arguments, I have the following code with the intention of
>> excluding this array,
>>
>> if (!arguments[counter][0].indexOf('_row2')) {
>> console.log(arguments[counter][0]);
>> }
>>
>> But the console did not return the value of 'grantor_row2'. What's
>> wrong?
>
> You are actually checking if the first element starts with "_row2".
No, they are very likely checking if the first item of the argument with
zero-based index “counter”, arguments[counter][0], does _not_ start with
"_row2".
Very likely arguments[counter][0] is a String value, "grantor_row2", so
arguments[counter][0].indexOf() would be equivalent to calling
String.prototype.indexOf() on arguments[counter][0]. That method returns,
as a Number value, the zero-based index of the start of its argument, the
substring (“needle”), within its “this” value, the searched string
(“haystack”); it returns -1 if the haystack does not contain the needle.
And any Number value *other than 0* results in Boolean “false” when it is
the operand of the Boolean Not (“!”) operator.
--
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 | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-09 11:20 -0700 |
| Message-ID | <f695cf44-131c-4eb8-9169-9b1406abadc1@googlegroups.com> |
| In reply to | #31520 |
Update:
First, currently I'm doing dynamic Table's TD(s) insertion.
generic function such as addSectionFunction('arg1','argu2') or
addSectionFunction('arg1','argu2','argu3') can work, however,
it's very limited. For instance, for the test case, I used INPUT and SIZE=15 for each of these arguments, well, in real world, I may need some of them to be INPUT and some of them checkbox or even date for HTML5 and even for the same INPUT type, some with SIZE of 15 while a few may need to be 60 something. This type of function and its argument call would not suffice to solve problem at hand.
Possible solution?
Thanks.
On Saturday, October 8, 2016 at 5:48:35 PM UTC-4, justaguy wrote:
> Hi,
>
> Could we create a generic function like the following?
> Genf = function () {
> // do stuff below
>
> };
>
> Then, call this function like
> Genf (arg1)
> Or
> Genf (arg1,arg2)
> ...
>
> And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
>
> Thanks.
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-09 12:10 -0700 |
| Message-ID | <00102670-1f70-4c19-9e90-8c010dd7a211@googlegroups.com> |
| In reply to | #31540 |
Grammar correction.
"it's very limited" -> "it's very limiting" (better English)
On Sunday, October 9, 2016 at 2:20:05 PM UTC-4, justaguy wrote:
> Update:
>
> First, currently I'm doing dynamic Table's TD(s) insertion.
> generic function such as addSectionFunction('arg1','argu2') or
> addSectionFunction('arg1','argu2','argu3') can work, however,
> it's very limited. For instance, for the test case, I used INPUT and SIZE=15 for each of these arguments, well, in real world, I may need some of them to be INPUT and some of them checkbox or even date for HTML5 and even for the same INPUT type, some with SIZE of 15 while a few may need to be 60 something. This type of function and its argument call would not suffice to solve problem at hand.
>
> Possible solution?
>
> Thanks.
>
> On Saturday, October 8, 2016 at 5:48:35 PM UTC-4, justaguy wrote:
> > Hi,
> >
> > Could we create a generic function like the following?
> > Genf = function () {
> > // do stuff below
> >
> > };
> >
> > Then, call this function like
> > Genf (arg1)
> > Or
> > Genf (arg1,arg2)
> > ...
> >
> > And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
> >
> > Thanks.
[toc] | [prev] | [next] | [standalone]
| From | justaguy <lichunshen84@gmail.com> |
|---|---|
| Date | 2016-10-10 17:05 -0700 |
| Message-ID | <284de9db-c176-422e-8f46-8d5df57e233e@googlegroups.com> |
| In reply to | #31520 |
Hi all,
This is an update, thus, top posting. Anyway, I got the function to work as expected and I'd like to drop a line to thank each of you.
On Saturday, October 8, 2016 at 5:48:35 PM UTC-4, justaguy wrote:
> Hi,
>
> Could we create a generic function like the following?
> Genf = function () {
> // do stuff below
>
> };
>
> Then, call this function like
> Genf (arg1)
> Or
> Genf (arg1,arg2)
> ...
>
> And if it'still doable, do we habe something like arguments.length? So that we an loop through for each argument.
>
> Thanks.
[toc] | [prev] | [standalone]
Back to top | Article view | comp.lang.javascript
csiph-web