Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #36868 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2019-06-12 14:40 -0700 |
| Last post | 2019-06-13 04:20 -0700 |
| Articles | 10 on this page of 30 — 5 participants |
Back to article view | Back to comp.lang.javascript
Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-12 14:40 -0700
Re: Rudimentary programming methodology "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-12 23:54 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-12 23:41 -0700
Re: Rudimentary programming methodology Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 11:27 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-12 23:56 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 00:49 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 00:57 -0700
Re: Rudimentary programming methodology Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 11:31 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:19 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:21 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:26 -0700
Re: Rudimentary programming methodology Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 13:43 +0200
Re: Rudimentary programming methodology Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 11:29 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:13 -0700
Re: Rudimentary programming methodology "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-13 12:24 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:36 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:48 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 03:56 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 04:01 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 04:03 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 04:10 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-13 04:14 -0700
Re: Rudimentary programming methodology Arno Welzel <usenet@arnowelzel.de> - 2019-06-13 13:45 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-15 03:36 -0700
Re: Rudimentary programming methodology "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2019-06-15 13:49 +0200
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-15 06:31 -0700
Re: Rudimentary programming methodology dr.j.r.stockton@gmail.com - 2019-06-15 07:40 -0700
Re: Rudimentary programming methodology Jonas Thörnvall <jonas.thornvall@gmail.com> - 2019-06-15 08:25 -0700
Re: Rudimentary programming methodology JJ <jj4public@vfemail.net> - 2019-06-13 15:13 +0700
Re: Rudimentary programming methodology dr.j.r.stockton@gmail.com - 2019-06-13 04:20 -0700
Page 2 of 2 — ← Prev page 1 [2]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-06-13 04:10 -0700 |
| Message-ID | <0af38ccd-784d-408e-87ce-6a34c9dc7b5a@googlegroups.com> |
| In reply to | #36894 |
Den torsdag 13 juni 2019 kl. 13:01:26 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 13 juni 2019 kl. 12:48:45 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 13 juni 2019 kl. 12:36:51 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 13 juni 2019 kl. 12:24:42 UTC+2 skrev Evertjan.:
> > > > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 13
> > > > Jun 2019 in comp.lang.javascript:
> > > >
> > > > > Well Arno Evertjan claimed that javscript switch is just a fancy layout
> > > > > and doing if else if in background. So it is just a reading aid for
> > > > > code.
> > > >
> > > > No, you should not try to read between the lines.
> > > >
> > > > A switch DOES the same in the background as a if-then-else construct does,
> > > > but IS NOT the same.
> > > >
> > > > You can easily measure any timing improvement by setting up a test script.
> > > >
> > > > > But maybe he was just trying to pull a joke upon me.
> > > >
> > > > This is the first sensible idea you have,
> > > > you should always be prepared for that.
> > > >
> > > > After all, forgetting the sex thing, there is only one thing more enjoyable
> > > > than discussing by arguments, and that is exchanging jokes.
> > > >
> > > > PS: the discussion being more educational.
> > > >
> > > > --
> > > > Evertjan.
> > > > The Netherlands.
> > > > (Please change the x'es to dots in my emailaddress)
> > >
> > > Well you make me confused Evertjan is there a sequential case evaluation until break, or is case basicly a function call to the appropriate case?
> > >
> > > If it is not, why does not javascript have a construct more like this pseudocode where Case basicly a variable assigned to hold a function call?
> > >
> > > Case A {do this}
> > > Case B {do that}
> > > Case C {do something else}
> > >
> > > If switch=A {Case:A)} else if switch=B {Case:B)}elseif switch=C {Case:C}
> > >
> > > start process
> > > do Case;
> > > end process
> >
> > This syntax would probably be more suitable for javascript.
> >
> > Case(A) {do this}
> > Case(B) {do that}
> > Case(C) {do something else}
> >
> > If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
> >
> >
> > setTimeout(function(){Case(x);}, 300);
> >
> > Well i know that x is normally a function parameter, and there is no syntax appropriate but since Case probably a reserved word i see no problem with it.
> >
> > I think it is rather beautiful in its simplicity?
>
> Well maybe you lke this syntax better.
>
> Case:A {do this}
> Case:B {do that}
> Case:C {do something else}
>
> If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
>
>
> setTimeout(function(){Case:(x);}, 300)
And for the anal retentive i suggest
Case:"A" {do this}
Case:"B" {do that}
Case:"C" {do something else}
If (switch==A) {x="A")} else if (switch==B) {x="B")} elseif (switch==C) {x="C"}
setTimeout(function(){Case:(x);}, 300)
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-06-13 04:14 -0700 |
| Message-ID | <95daa00e-2297-437d-90ba-ea18b52fea9f@googlegroups.com> |
| In reply to | #36898 |
Den torsdag 13 juni 2019 kl. 13:10:20 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 13 juni 2019 kl. 13:01:26 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 13 juni 2019 kl. 12:48:45 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 13 juni 2019 kl. 12:36:51 UTC+2 skrev Jonas Thörnvall:
> > > > Den torsdag 13 juni 2019 kl. 12:24:42 UTC+2 skrev Evertjan.:
> > > > > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 13
> > > > > Jun 2019 in comp.lang.javascript:
> > > > >
> > > > > > Well Arno Evertjan claimed that javscript switch is just a fancy layout
> > > > > > and doing if else if in background. So it is just a reading aid for
> > > > > > code.
> > > > >
> > > > > No, you should not try to read between the lines.
> > > > >
> > > > > A switch DOES the same in the background as a if-then-else construct does,
> > > > > but IS NOT the same.
> > > > >
> > > > > You can easily measure any timing improvement by setting up a test script.
> > > > >
> > > > > > But maybe he was just trying to pull a joke upon me.
> > > > >
> > > > > This is the first sensible idea you have,
> > > > > you should always be prepared for that.
> > > > >
> > > > > After all, forgetting the sex thing, there is only one thing more enjoyable
> > > > > than discussing by arguments, and that is exchanging jokes.
> > > > >
> > > > > PS: the discussion being more educational.
> > > > >
> > > > > --
> > > > > Evertjan.
> > > > > The Netherlands.
> > > > > (Please change the x'es to dots in my emailaddress)
> > > >
> > > > Well you make me confused Evertjan is there a sequential case evaluation until break, or is case basicly a function call to the appropriate case?
> > > >
> > > > If it is not, why does not javascript have a construct more like this pseudocode where Case basicly a variable assigned to hold a function call?
> > > >
> > > > Case A {do this}
> > > > Case B {do that}
> > > > Case C {do something else}
> > > >
> > > > If switch=A {Case:A)} else if switch=B {Case:B)}elseif switch=C {Case:C}
> > > >
> > > > start process
> > > > do Case;
> > > > end process
> > >
> > > This syntax would probably be more suitable for javascript.
> > >
> > > Case(A) {do this}
> > > Case(B) {do that}
> > > Case(C) {do something else}
> > >
> > > If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
> > >
> > >
> > > setTimeout(function(){Case(x);}, 300);
> > >
> > > Well i know that x is normally a function parameter, and there is no syntax appropriate but since Case probably a reserved word i see no problem with it.
> > >
> > > I think it is rather beautiful in its simplicity?
> >
> > Well maybe you lke this syntax better.
> >
> > Case:A {do this}
> > Case:B {do that}
> > Case:C {do something else}
> >
> > If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
> >
> >
> > setTimeout(function(){Case:(x);}, 300)
>
> And for the anal retentive i suggest
>
> Case:"A" {do this}
> Case:"B" {do that}
> Case:"C" {do something else}
>
> If (switch==A) {x="A")} else if (switch==B) {x="B")} elseif (switch==C) {x="C"}
>
>
> setTimeout(function(){Case:(x);}, 300)
Could i ask why does it work like it does today "as an overlay", and not like real switches?
[toc] | [prev] | [next] | [standalone]
| From | Arno Welzel <usenet@arnowelzel.de> |
|---|---|
| Date | 2019-06-13 13:45 +0200 |
| Message-ID | <gmeratFheehU2@mid.individual.net> |
| In reply to | #36899 |
On 13.06.19 13:14, Jonas Thörnvall wrote: > Den torsdag 13 juni 2019 kl. 13:10:20 UTC+2 skrev Jonas Thörnvall: >> Den torsdag 13 juni 2019 kl. 13:01:26 UTC+2 skrev Jonas Thörnvall: >>> Den torsdag 13 juni 2019 kl. 12:48:45 UTC+2 skrev Jonas Thörnvall: >>>> Den torsdag 13 juni 2019 kl. 12:36:51 UTC+2 skrev Jonas Thörnvall: [...] Are you serious? Usenet is *NOT* a chat room. -- Arno Welzel https://arnowelzel.de
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-06-15 03:36 -0700 |
| Message-ID | <2e28427c-c835-4e61-bdd1-04ac49d9a372@googlegroups.com> |
| In reply to | #36898 |
Den torsdag 13 juni 2019 kl. 13:10:20 UTC+2 skrev Jonas Thörnvall:
> Den torsdag 13 juni 2019 kl. 13:01:26 UTC+2 skrev Jonas Thörnvall:
> > Den torsdag 13 juni 2019 kl. 12:48:45 UTC+2 skrev Jonas Thörnvall:
> > > Den torsdag 13 juni 2019 kl. 12:36:51 UTC+2 skrev Jonas Thörnvall:
> > > > Den torsdag 13 juni 2019 kl. 12:24:42 UTC+2 skrev Evertjan.:
> > > > > =?UTF-8?Q?Jonas_Th=C3=B6rnvall?= <jonas.thornvall@gmail.com> wrote on 13
> > > > > Jun 2019 in comp.lang.javascript:
> > > > >
> > > > > > Well Arno Evertjan claimed that javscript switch is just a fancy layout
> > > > > > and doing if else if in background. So it is just a reading aid for
> > > > > > code.
> > > > >
> > > > > No, you should not try to read between the lines.
> > > > >
> > > > > A switch DOES the same in the background as a if-then-else construct does,
> > > > > but IS NOT the same.
> > > > >
> > > > > You can easily measure any timing improvement by setting up a test script.
> > > > >
> > > > > > But maybe he was just trying to pull a joke upon me.
> > > > >
> > > > > This is the first sensible idea you have,
> > > > > you should always be prepared for that.
> > > > >
> > > > > After all, forgetting the sex thing, there is only one thing more enjoyable
> > > > > than discussing by arguments, and that is exchanging jokes.
> > > > >
> > > > > PS: the discussion being more educational.
> > > > >
> > > > > --
> > > > > Evertjan.
> > > > > The Netherlands.
> > > > > (Please change the x'es to dots in my emailaddress)
> > > >
> > > > Well you make me confused Evertjan is there a sequential case evaluation until break, or is case basicly a function call to the appropriate case?
> > > >
> > > > If it is not, why does not javascript have a construct more like this pseudocode where Case basicly a variable assigned to hold a function call?
> > > >
> > > > Case A {do this}
> > > > Case B {do that}
> > > > Case C {do something else}
> > > >
> > > > If switch=A {Case:A)} else if switch=B {Case:B)}elseif switch=C {Case:C}
> > > >
> > > > start process
> > > > do Case;
> > > > end process
> > >
> > > This syntax would probably be more suitable for javascript.
> > >
> > > Case(A) {do this}
> > > Case(B) {do that}
> > > Case(C) {do something else}
> > >
> > > If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
> > >
> > >
> > > setTimeout(function(){Case(x);}, 300);
> > >
> > > Well i know that x is normally a function parameter, and there is no syntax appropriate but since Case probably a reserved word i see no problem with it.
> > >
> > > I think it is rather beautiful in its simplicity?
> >
> > Well maybe you lke this syntax better.
> >
> > Case:A {do this}
> > Case:B {do that}
> > Case:C {do something else}
> >
> > If (switch==A) {x=A)} else if (switch==B) {x=B)} elseif (switch==C) {x=C}
> >
> >
> > setTimeout(function(){Case:(x);}, 300)
>
> And for the anal retentive i suggest
>
> Case:"A" {do this}
> Case:"B" {do that}
> Case:"C" {do something else}
>
> If (switch==A) {x="A")} else if (switch==B) {x="B")} elseif (switch==C) {x="C"}
>
>
> setTimeout(function(){Case:(x);}, 300)
Ok i found an example. I like that variables can be assigned functions ***approved***.
<HTML>
<HEAD></HEAD>
<script>
function a() {
alert('A!');
};
function b() {
alert('B!');
};
function c() {
alert('C!');
};
var x = c;
x();
</script>
<BODY>
TEST
</BODY>
</HTML>
[toc] | [prev] | [next] | [standalone]
| From | "Evertjan." <exxjxw.hannivoort@inter.nl.net> |
|---|---|
| Date | 2019-06-15 13:49 +0200 |
| Message-ID | <XnsAA6F8CAE97E71eejj99@194.109.6.166> |
| In reply to | #36919 |
<jonas.thornvall@gmail.com> wrote on 15 Jun 2019 in comp.lang.javascript:
> Ok i found an example. I like that variables can be assigned functions
Wrong point of view.
Variables, objects and functions need a **name** to be used,
which **name** points to such variable, object or function.
This **name** can be reassigned,
as long as they are not created with 'const ..'.
let a1 = 7;
const a2 = 8;
let f1 = (x) => {return x*x};
const f2 = (y) => {return y+y};
let ob1 = {};
const obj2 = {};
The names created with **let**
can be reassigned to any other type:
let a = 6;
a = (x) => 2*x;
a(7); // 14
a = [33,44];
a[1]; // 44
a[7]; undefined
a(7); Uncaught TypeError: a is not a function
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-06-15 06:31 -0700 |
| Message-ID | <684affc3-94cd-42f0-8410-1ec09ae2e6c6@googlegroups.com> |
| In reply to | #36923 |
Den lördag 15 juni 2019 kl. 13:49:51 UTC+2 skrev Evertjan.:
> <jonas.thornvall@gmail.com> wrote on 15 Jun 2019 in comp.lang.javascript:
>
> > Ok i found an example. I like that variables can be assigned functions
>
> Wrong point of view.
>
> Variables, objects and functions need a **name** to be used,
> which **name** points to such variable, object or function.
>
> This **name** can be reassigned,
> as long as they are not created with 'const ..'.
>
> let a1 = 7;
> const a2 = 8;
>
> let f1 = (x) => {return x*x};
> const f2 = (y) => {return y+y};
>
> let ob1 = {};
> const obj2 = {};
>
> The names created with **let**
> can be reassigned to any other type:
>
> let a = 6;
>
> a = (x) => 2*x;
> a(7); // 14
>
> a = [33,44];
> a[1]; // 44
> a[7]; undefined
> a(7); Uncaught TypeError: a is not a function
>
> --
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)
Well i if c really a name one would wonder why it is not var x = "c", but maybe then your in conflict with regular strings.
Well for me x is just a container holding a "string" used to find appropriate function. It looks a bit sloppy but it works, and have simple syntax i like it.
[toc] | [prev] | [next] | [standalone]
| From | dr.j.r.stockton@gmail.com |
|---|---|
| Date | 2019-06-15 07:40 -0700 |
| Message-ID | <9666855a-f0eb-4228-a63a-8fd56d603b8f@googlegroups.com> |
| In reply to | #36919 |
On Saturday, 15 June 2019 11:36:14 UTC+1, Jonas Thörnvall wrote: > Ok i found an example. I like that variables can be assigned functions ***approved***. I told you that two days ago. -- (c) John Stockton, near London, UK. Using Google Groups. | Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2019-06-15 08:25 -0700 |
| Message-ID | <8d3a4851-82fa-43fe-9a0a-65fc5c2ac6e8@googlegroups.com> |
| In reply to | #36925 |
Den lördag 15 juni 2019 kl. 16:40:09 UTC+2 skrev dr.j.r...@gmail.com: > On Saturday, 15 June 2019 11:36:14 UTC+1, Jonas Thörnvall wrote: > > > Ok i found an example. I like that variables can be assigned functions ***approved***. > > I told you that two days ago. > > -- > (c) John Stockton, near London, UK. Using Google Groups. | > Mail: J.R.""""""""@physics.org - or as Reply-To, if any. | Yeah you mah have done that in an incredible contrieved way...
[toc] | [prev] | [next] | [standalone]
| From | JJ <jj4public@vfemail.net> |
|---|---|
| Date | 2019-06-13 15:13 +0700 |
| Message-ID | <1u05fxsjxtucj.x38v6gbjncu1$.dlg@40tude.net> |
| In reply to | #36868 |
On Wed, 12 Jun 2019 14:40:46 -0700 (PDT), Jonas Thörnvall wrote:
> I have a problem that i should know howto solve it is probably very basic.
>
> Normally when you have choices, the most common way is to solve it with
> if, else if.
>
> But sometimes your choices is fundamental to a process, so they are the
> input parmeters for something.
>
> In my case i have a metronome, but depending on the "synth/hardware" you
> want to use you simply select it from an option list.
>
> And now i could do
>
> if (met=="external") {something sent to port)
> else if (met=="othersynth") {something else sent to port}
> else if (met=="anothersynth") {something else sent to port}
>
> If these are timed events it is not that effective to do this x times a
> second.
>
> So you just want check and set the case once? and then be used everytime
> during the interval?
>
> I guess that means to breakout the if cases into functions? But you just
> want the actual function call to differ, but not be checked every time
> you send something to the metronome.
>
> Basicly about setting what function to be called once, like flipping a
> switch and then it always take that "path".
>
> I have a slight memory it could be case programming using switches, but i
> don't quite see hot it applies dealing with timed events during an
> interval?
>
> Basicly i want to replace if else if before every metronome event.
If the code is like this:
if (met=="external") { func1(data1) }
else if (met=="othersynth") { func2(data2 }
else if (met=="anothersynth") { func3(data3) }
You might want to use two variables to store the function and its arguments.
e.g. `dataSender` and `dataToSend`.
First, at program initialization, declare and set the initial value of the
variables. e.g.
var dataSender = func1;
var dataToSend = data1;
Do this in the timer handler.
dataSender(dataToSend);
If `dataSender` function uses multiple arguments and `dataToSend` is an
array for the function arguments, call it like this.
dataSender.apply(this, dataToSend);
Place below code to update the variables after the `met` variable is
modified.
if (met=="external") {
dataSender = func1; dataToSend = data1;
}
else if (met=="othersynth") {
dataSender = func2; dataToSend = data2;
}
else if (met=="anothersynth") {
dataSender = func3; dataToSend = data3;
}
The variable initialization and update can be simplified like this.
Initialization: (after `met` variable is defined)
var metronomeData = {
external: { func: func1, data: data1 },
othersynth: { func: func2, data: data2 },
anothersynth: { func: func3, data: data3 }
};
var dataSender = metronomeData[met].func;
var dataToSend = metronomeData[met].data;
Update:
dataSender = metronomeData[met].func;
dataToSend = metronomeData[met].data;
So, with this method, the timer handler only need to do a function call. It
doesn't need to do any condition check. The code which handles the "switch
flipping" will be the one that check the `met` variable, as well as changing
the metronome function and its data.
[toc] | [prev] | [next] | [standalone]
| From | dr.j.r.stockton@gmail.com |
|---|---|
| Date | 2019-06-13 04:20 -0700 |
| Message-ID | <3cc88e00-a43f-4ab7-95a7-4adf83f6ca72@googlegroups.com> |
| In reply to | #36868 |
On Wednesday, 12 June 2019 22:40:56 UTC+1, Jonas Thörnvall wrote:
Before you continue with JavaScript in Usenet, it would be helpful if you were to learn how to write easily-understandable English. Until you have achieved that, I suggest that you write and post your articles in two parts.
The first part would be written in a simple way using your favoured Scandiwegian language - some of will be able to read that directly, or with the aid of an associate, and Google Translate makes a reasonable job of translating the commoner Western European languages into <s>English</s> American.
The second part would be written, as at present, on what you think is English, and you can do that by merely improving a Google translation.
Readers could therefore by guided by one or both versions - and might even begin to learn some Scandiwegian.
You could also use a spelling-checker
> I have a problem that i should know howto solve it is probably very basic.
>
> Normally when you have choices, the most common way is to solve it with if, else if.
Commonness is irrelevant. One should also be familiar with
A ? B : C
and with the use of switch+case
> But sometimes your choices is fundamental to a process, so they are the input parmeters for something.
>
> In my case i have a metronome, but depending on the "synth/hardware" you want to use you simply select it from an option list.
>
> And now i could do
>
> if (met=="external") {something sent to port)
> else if (met=="othersynth") {something else sent to port}
> else if (met=="anothersynth") {something else sent to port}
If speed may matter, and those tests will be repeated with 'met' unable to change in between, then the (relatively slow) string comparisons should be done once only after each possible change of 'met'; so, for example,
var metexternal = met=="external"
...
if (metexternal) { ... }
A JavaScript engine might do that optimisation before execution; but I would not choose to assume that.
> If these are timed events it is not that effective to do this x times a second.
> So you just want check and set the case once? and then be used everytime during the interval?
>
> I guess that means to breakout the if cases into functions?
> But you just want the actual function call to differ, but not be checked every time you send something to the metronome.
>
> Basicly about setting what function to be called once, like flipping a switch and then it always take that "path".
>
> I have a slight memory it could be case programming using switches, but i don't quite see hot it applies dealing with timed events during an interval?
>
> Basicly i want to replace if else if before every metronome event.
Remember that functions can be assigned : this, if functions 'dogwash' and 'catwash' are already defined, one can write
petwash = itWoofs ? dogwash : catwash
and subsequently call 'petwash' as a function.
--
(c) John Stockton, near London, UK. Using Google Groups. |
Mail: J.R.""""""""@physics.org - or as Reply-To, if any. |
[toc] | [prev] | [standalone]
Page 2 of 2 — ← Prev page 1 [2]
Back to top | Article view | comp.lang.javascript
csiph-web