Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #34581 > unrolled thread
| Started by | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| First post | 2018-01-18 02:50 -0800 |
| Last post | 2018-01-21 00:55 -0800 |
| Articles | 20 on this page of 35 — 5 participants |
Back to article view | Back to comp.lang.javascript
Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 02:50 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 03:03 -0800
Re: Get the object structure correct. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-18 14:39 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 16:38 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 16:56 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 17:19 -0800
Re: Get the object structure correct. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-18 17:33 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 19:54 -0800
Re: Get the object structure correct. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-19 04:55 +0100
Re: Get the object structure correct. "Mark-" <nospam@mapson.xyz> - 2018-01-19 04:03 +0000
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 20:06 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 20:30 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 20:49 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 00:12 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 02:01 -0800
Re: Get the object structure correct. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-25 07:49 +0100
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-30 01:06 -0800
Re: Get the object structure correct. Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2018-01-30 11:01 +0100
Re: Get the object structure correct. "Mark-" <nospam@mapson.xyz> - 2018-01-30 13:37 +0000
Re: Get the object structure correct. John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-30 19:14 +0000
Re: Get the object structure correct. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-18 17:24 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 17:41 -0800
Re: Get the object structure correct. "Michael Haufe (TNO)" <tno@thenewobjective.com> - 2018-01-18 17:47 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 18:29 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 18:46 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 18:54 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-18 19:00 -0800
Re: Get the object structure correct. John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-19 11:20 +0000
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 11:48 -0800
Re: Get the object structure correct. John G Harris <niam@jghnorth.org.uk.invalid> - 2018-01-19 20:03 +0000
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 12:18 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 12:48 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-19 13:02 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-20 18:07 -0800
Re: Get the object structure correct. Jonas Thörnvall <jonas.thornvall@gmail.com> - 2018-01-21 00:55 -0800
Page 1 of 2 [1] 2 Next page →
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 02:50 -0800 |
| Subject | Get the object structure correct. |
| Message-ID | <72f939d0-d998-41d0-a393-0909c777d969@googlegroups.com> |
function makeTrack()
{
for (var m = 0; m < 101; m ++ )
{
track[m] ={
outport:[],
portname : [],
midichannel:[],
program:[],
time:[],
data0:[],
data1:[],
data2:[]
};
}
defaultTrack();
return track;
}
Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
How can i write an object where data0,data1,data2 as properties of time?
[toc] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 03:03 -0800 |
| Message-ID | <cb222a47-9240-4881-b08b-3959b51ab920@googlegroups.com> |
| In reply to | #34581 |
Den torsdag 18 januari 2018 kl. 11:50:35 UTC+1 skrev Jonas Thörnvall:
> function makeTrack()
> {
> for (var m = 0; m < 101; m ++ )
> {
> track[m] ={
> outport:[],
> portname : [],
> midichannel:[],
> program:[],
> time:[],
> data0:[],
> data1:[],
> data2:[]
> };
> }
> defaultTrack();
> return track;
> }
>
> Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
>
> How can i write an object where data0,data1,data2 as properties of time?
Well to be properties of time rather then arrays?
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2018-01-18 14:39 -0800 |
| Message-ID | <f6b3e8f5-223d-406b-9059-b380aae53aa6@googlegroups.com> |
| In reply to | #34581 |
Jonas Thörnvall wrote:
> function makeTrack()
> {
> for (var m = 0; m < 101; m ++ )
> {
> track[m] ={
> outport:[],
> portname : [],
> midichannel:[],
> program:[],
> time:[],
> data0:[],
> data1:[],
> data2:[]
> };
> }
> defaultTrack();
> return track;
> }
>
> Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
<script>
class Track{
constructor(id) {
this.id = id;
this.outport = [];
this.midichannel = [];
this.portname = [];
this.program = [];
this.time = [];
this.data0 = [];
this.data1 = [];
this.data2 = [];
}
toString(){ return `new Track(${this.id})`}
}
// generate 100 tracks
let tracks = Array.from({length:101},(_,i) => new Track(i))
//reverse order
tracks.sort((a,b) => b.id - a.id)
// convert to string
tracks.join(",")
</script>
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 16:38 -0800 |
| Message-ID | <6a8311a3-4cd1-4d3d-b127-b7295255d85d@googlegroups.com> |
| In reply to | #34583 |
Den torsdag 18 januari 2018 kl. 23:39:39 UTC+1 skrev Michael Haufe (TNO):
> Jonas Thörnvall wrote:
> > function makeTrack()
> > {
> > for (var m = 0; m < 101; m ++ )
> > {
> > track[m] ={
> > outport:[],
> > portname : [],
> > midichannel:[],
> > program:[],
> > time:[],
> > data0:[],
> > data1:[],
> > data2:[]
> > };
> > }
> > defaultTrack();
> > return track;
> > }
> >
> > Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
>
> <script>
> class Track{
> constructor(id) {
> this.id = id;
> this.outport = [];
> this.midichannel = [];
> this.portname = [];
> this.program = [];
> this.time = [];
> this.data0 = [];
> this.data1 = [];
> this.data2 = [];
> }
>
> toString(){ return `new Track(${this.id})`}
> }
>
> // generate 100 tracks
> let tracks = Array.from({length:101},(_,i) => new Track(i))
>
> //reverse order
> tracks.sort((a,b) => b.id - a.id)
>
> // convert to string
> tracks.join(",")
> </script>
Hello Michael thanks for your answer i do not see how that would make dataX a property of time? But i confess i have very bad understanding of objects, and maybe do not understand your code.
Basicly i would like a structure that make
track[x].time.sort()
possible and since data0,data1,data2 would be "properties?" of time, that the only thing that would need to be done to sort the messages?
How would your structure make that possible?
I probably do not understand the constructor id
tracks.sort((a,b) => b.id - a.id)
And i do not understand what is sorted here, but my guess it is not timed events?
data0,data1,data2 are part of a message generated "for example" on keystroke they get a time code for the event.
You cannot overdub record, "splice" new messages/events in realtime **at least that is what i suspect** it cause latency.
So i have a playtrack ***mixtrack*** 0, that is played when you record selected track, but that mean the events will not be sorted until you stop recording.
First the events upon the recorded track is sorted by time[index] that is why i want data0,data1,data2 to be properties of time. Because then i can just sort them by track[x].time.sort(); correct?
Last step After each new recording to a track ***all selected tracks*** are downmixed to track zero. And sorted this is the mastertrack that play all events.
for (var i=0;i<track.length;track++){
track[i].time.sort();
}
To me the above, seem to be the way todo it, given that i can't see how timed events would be sorted using your approach?
I can really need the help here because if can do this, i think the actual functionality to play and record tracks -> "bar intervals" using metronome is done.
And i can go on to build first a bar overview/editor "copy,paste" a function to buildup song using snippets dragged on canvas. And later a graphical event editor.
I just would like to finnish the actual recording/play device first.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 16:56 -0800 |
| Message-ID | <31fb9b36-354d-44da-89eb-b84551977bc2@googlegroups.com> |
| In reply to | #34584 |
Den fredag 19 januari 2018 kl. 01:38:29 UTC+1 skrev Jonas Thörnvall:
> Den torsdag 18 januari 2018 kl. 23:39:39 UTC+1 skrev Michael Haufe (TNO):
> > Jonas Thörnvall wrote:
> > > function makeTrack()
> > > {
> > > for (var m = 0; m < 101; m ++ )
> > > {
> > > track[m] ={
> > > outport:[],
> > > portname : [],
> > > midichannel:[],
> > > program:[],
> > > time:[],
> > > data0:[],
> > > data1:[],
> > > data2:[]
> > > };
> > > }
> > > defaultTrack();
> > > return track;
> > > }
> > >
> > > Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
> >
> > <script>
> > class Track{
> > constructor(id) {
> > this.id = id;
> > this.outport = [];
> > this.midichannel = [];
> > this.portname = [];
> > this.program = [];
> > this.time = [];
> > this.data0 = [];
> > this.data1 = [];
> > this.data2 = [];
> > }
> >
> > toString(){ return `new Track(${this.id})`}
> > }
> >
> > // generate 100 tracks
> > let tracks = Array.from({length:101},(_,i) => new Track(i))
> >
> > //reverse order
> > tracks.sort((a,b) => b.id - a.id)
> >
> > // convert to string
> > tracks.join(",")
> > </script>
>
> Hello Michael thanks for your answer i do not see how that would make dataX a property of time? But i confess i have very bad understanding of objects, and maybe do not understand your code.
>
> Basicly i would like a structure that make
> track[x].time.sort()
>
> possible and since data0,data1,data2 would be "properties?" of time, that the only thing that would need to be done to sort the messages?
>
> How would your structure make that possible?
>
> I probably do not understand the constructor id
> tracks.sort((a,b) => b.id - a.id)
> And i do not understand what is sorted here, but my guess it is not timed events?
>
> data0,data1,data2 are part of a message generated "for example" on keystroke they get a time code for the event.
>
> You cannot overdub record, "splice" new messages/events in realtime **at least that is what i suspect** it cause latency.
>
> So i have a playtrack ***mixtrack*** 0, that is played when you record selected track, but that mean the events will not be sorted until you stop recording.
>
> First the events upon the recorded track is sorted by time[index] that is why i want data0,data1,data2 to be properties of time. Because then i can just sort them by track[x].time.sort(); correct?
>
> Last step After each new recording to a track ***all selected tracks*** are downmixed to track zero. And sorted this is the mastertrack that play all events.
>
> for (var i=0;i<track.length;track++){
> track[i].time.sort();
> }
>
> To me the above, seem to be the way todo it, given that i can't see how timed events would be sorted using your approach?
>
> I can really need the help here because if can do this, i think the actual functionality to play and record tracks -> "bar intervals" using metronome is done.
>
> And i can go on to build first a bar overview/editor "copy,paste" a function to buildup song using snippets dragged on canvas. And later a graphical event editor.
>
> I just would like to finnish the actual recording/play device first.
The structure should be like this i have a track array, each track hold an indexed message array "that store time".
Each "timed" event hold three single valued properties "integers" data0,data1,data2.
But my syntax skills in the language is not sufficient to buildup/make that structure "object or not" but i guess all structures in javascript are objects?
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 17:19 -0800 |
| Message-ID | <f576b7ec-3d71-42f3-89df-1c7126d2a898@googlegroups.com> |
| In reply to | #34585 |
Den fredag 19 januari 2018 kl. 01:56:48 UTC+1 skrev Jonas Thörnvall:
> Den fredag 19 januari 2018 kl. 01:38:29 UTC+1 skrev Jonas Thörnvall:
> > Den torsdag 18 januari 2018 kl. 23:39:39 UTC+1 skrev Michael Haufe (TNO):
> > > Jonas Thörnvall wrote:
> > > > function makeTrack()
> > > > {
> > > > for (var m = 0; m < 101; m ++ )
> > > > {
> > > > track[m] ={
> > > > outport:[],
> > > > portname : [],
> > > > midichannel:[],
> > > > program:[],
> > > > time:[],
> > > > data0:[],
> > > > data1:[],
> > > > data2:[]
> > > > };
> > > > }
> > > > defaultTrack();
> > > > return track;
> > > > }
> > > >
> > > > Try to get the object structure correct for easier sorting, i am pretty cluess about howto write objects the way i realy would like them. I probably could do an elaborate sort on the object above but it seem a bit of waste when javacript to have sort();
> > >
> > > <script>
> > > class Track{
> > > constructor(id) {
> > > this.id = id;
> > > this.outport = [];
> > > this.midichannel = [];
> > > this.portname = [];
> > > this.program = [];
> > > this.time = [];
> > > this.data0 = [];
> > > this.data1 = [];
> > > this.data2 = [];
> > > }
> > >
> > > toString(){ return `new Track(${this.id})`}
> > > }
> > >
> > > // generate 100 tracks
> > > let tracks = Array.from({length:101},(_,i) => new Track(i))
> > >
> > > //reverse order
> > > tracks.sort((a,b) => b.id - a.id)
> > >
> > > // convert to string
> > > tracks.join(",")
> > > </script>
> >
> > Hello Michael thanks for your answer i do not see how that would make dataX a property of time? But i confess i have very bad understanding of objects, and maybe do not understand your code.
> >
> > Basicly i would like a structure that make
> > track[x].time.sort()
> >
> > possible and since data0,data1,data2 would be "properties?" of time, that the only thing that would need to be done to sort the messages?
> >
> > How would your structure make that possible?
> >
> > I probably do not understand the constructor id
> > tracks.sort((a,b) => b.id - a.id)
> > And i do not understand what is sorted here, but my guess it is not timed events?
> >
> > data0,data1,data2 are part of a message generated "for example" on keystroke they get a time code for the event.
> >
> > You cannot overdub record, "splice" new messages/events in realtime **at least that is what i suspect** it cause latency.
> >
> > So i have a playtrack ***mixtrack*** 0, that is played when you record selected track, but that mean the events will not be sorted until you stop recording.
> >
> > First the events upon the recorded track is sorted by time[index] that is why i want data0,data1,data2 to be properties of time. Because then i can just sort them by track[x].time.sort(); correct?
> >
> > Last step After each new recording to a track ***all selected tracks*** are downmixed to track zero. And sorted this is the mastertrack that play all events.
> >
> > for (var i=0;i<track.length;track++){
> > track[i].time.sort();
> > }
> >
> > To me the above, seem to be the way todo it, given that i can't see how timed events would be sorted using your approach?
> >
> > I can really need the help here because if can do this, i think the actual functionality to play and record tracks -> "bar intervals" using metronome is done.
> >
> > And i can go on to build first a bar overview/editor "copy,paste" a function to buildup song using snippets dragged on canvas. And later a graphical event editor.
> >
> > I just would like to finnish the actual recording/play device first.
>
> The structure should be like this i have a track array, each track hold an indexed message array "that store time".
> Each "timed" event hold three single valued properties "integers" data0,data1,data2.
>
> But my syntax skills in the language is not sufficient to buildup/make that structure "object or not" but i guess all structures in javascript are objects?
Well i try to look at examples but the syntax just over myhead.
var People = [
{Name: "Name", Surname: "Surname"},
{Name:"AAA", Surname:"ZZZ"},
{Name: "Name", Surname: "AAA"}
];
I guess people is an array holding three indexes above?
The properties of people is Name and Surname
So i can set Peoples properties by
People[3].Name="Jonas";
People[3].Surname="Thörnvall";
Right?
If i try to translate it using my mind to my example i end up with this?
It is hard when the structure of language syntax turns into guesswork.
for (var m = 0; m < 101; m ++ )
{
track[m] ={
outport:[],
portname : [],
midichannel:[],
program:[],
time:[{data0:0, data1:0, data2:0}]
};
}
return track;
}
[toc] | [prev] | [next] | [standalone]
| From | "Michael Haufe (TNO)" <tno@thenewobjective.com> |
|---|---|
| Date | 2018-01-18 17:33 -0800 |
| Message-ID | <1fa87bbc-8c47-4290-8757-a3de5ce828b6@googlegroups.com> |
| In reply to | #34586 |
Jonas Thörnvall wrote:
> Well i try to look at examples but the syntax just over myhead.
>
> var People = [
> {Name: "Name", Surname: "Surname"},
> {Name:"AAA", Surname:"ZZZ"},
> {Name: "Name", Surname: "AAA"}
> ];
> I guess people is an array holding three indexes above?
> The properties of people is Name and Surname
JavaScript developers have a tendency to "golf" [1] their code just like Perl programmers. Which can make things unnecessarily terse.
I would have wrote the example like this:
</script>
class Person {
constructor(name, surName) {
this.name = name;
this.surName = surName
}
}
var people = [
new Person(Brendan", "Eich"),
new Person("Alan","Kay"),
new Person("Robert", "Carlyle")
]
people.push(new Person("Jonas", "Thörnvall"))
</script>
[1] <https://en.wikipedia.org/wiki/Code_golf>
> So i can set Peoples properties by
> People[3].Name="Jonas";
> People[3].Surname="Thörnvall";
> Right?
Right, you could, but the meaning of those objects are implied. My example is explicit.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 19:54 -0800 |
| Message-ID | <619f22c0-742a-46d0-bf33-fa4a7daa7374@googlegroups.com> |
| In reply to | #34588 |
Den fredag 19 januari 2018 kl. 02:33:49 UTC+1 skrev Michael Haufe (TNO):
> Jonas Thörnvall wrote:
>
> > Well i try to look at examples but the syntax just over myhead.
> >
> > var People = [
> > {Name: "Name", Surname: "Surname"},
> > {Name:"AAA", Surname:"ZZZ"},
> > {Name: "Name", Surname: "AAA"}
> > ];
> > I guess people is an array holding three indexes above?
> > The properties of people is Name and Surname
>
> JavaScript developers have a tendency to "golf" [1] their code just like Perl programmers. Which can make things unnecessarily terse.
>
> I would have wrote the example like this:
>
> </script>
> class Person {
> constructor(name, surName) {
> this.name = name;
> this.surName = surName
> }
> }
>
> var people = [
> new Person(Brendan", "Eich"),
> new Person("Alan","Kay"),
> new Person("Robert", "Carlyle")
> ]
>
> people.push(new Person("Jonas", "Thörnvall"))
> </script>
>
>
> [1] <https://en.wikipedia.org/wiki/Code_golf>
>
> > So i can set Peoples properties by
> > People[3].Name="Jonas";
> > People[3].Surname="Thörnvall";
> > Right?
>
> Right, you could, but the meaning of those objects are implied. My example is explicit.
I decided to dwelve into the mysteries of objects reading your code, i can see the constructor similar to record from COBOL. It is just a construct hold no data.
Then you have a variable people that is an array, could been empty to start with but you show as example var people[];
No problems, and then you use the constructor Person to push in a new member? into the variable people. So people is an instance object of Person,we could have many variables using the class constructor Person holding different persons.
What is the time difference between push an object vs assign and read values to/from array?
Because messages objects will be created on the fly pressing keys, but also must be accessed on the fly "read" depending on timer. That is a concern that push objects and read them is slower then array handling.
I can do a constuctor just for fun.
class Track {
constructor(port,midichannel,program,midimessage) {
this.tracknr=tracknr;
this.port = port;
this.midichannel = midichannel;
this.midiprogram = program;
this.midimessage = midimessage;
}
}
class midimessage {
constructor(port,midichannel,program,midimessage) {
this.time = time;
this.data0 = data0;
this.data1 = data1;
this.data2 = data2;
}
}
But i have a message object with properties, is that a class in its own?
I do not understand how to make an object where properties have have?
"A property midimessage of track that hold, properties of it own?"
Maybe it is not even necessary but i do not like the application to shuffle unnecessary data? There is no point to shuffle trackdata creating a new message object but the messages still need to be connected to a track?
Is there subclassing, but then there is even more new syntax to learn.
I honestly prefer if someone show me howto create new midimessages using my old structure.
function makeTrack()
{
for (var m = 0; m < 101; m ++ )
{
track[m] ={
outport:[],
portname : [],
midichannel:[],
program:[],
midimessage:[{time:0,data0:0,data1:0,data2:0}]
};
}
defaultTrackValues();
return track;
}
function defaultTrackValues(){
for (var m = 1; m < 16; m ++ ){
track[m].outport[0]=document.getElementById("out_portsel").selectedIndex;
track[m].portname[0]=document.getElementById("out_portsel").value;
track[m].midichannel[0]=m;
track[m].program[0]=document.getElementById("prog_sel").value;
}
}
//Below function where i record them but i have not created any messageobjects.<
//So not working
//How can i either use new to create midimessages
//Or should i do like with track create messages?
function record(message){
clock=clock+rs;
midievent++;
track[tracknr].midimessage[x].time=clock;
track[tracknr].midimessage[x].data0= message.data[0];
track[tracknr].midimessage[x].data1= message.data[1];
track[tracknr].midimessage[x].data2= message.data[2];
x++;
console.log("Track="+tracknr);
}
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-01-19 04:55 +0100 |
| Message-ID | <2363754.U4In554KqX@PointedEars.de> |
| In reply to | #34588 |
Michael Haufe (TNO) wrote:
> Jonas Thörnvall wrote:
>> var People = [
>> {Name: "Name", Surname: "Surname"},
>> {Name:"AAA", Surname:"ZZZ"},
>> {Name: "Name", Surname: "AAA"}
>> ];
>> I guess people is an array holding three indexes above?
>> The properties of people is Name and Surname
>
> JavaScript developers have a tendency to "golf" [1] their code just like
> Perl programmers. Which can make things unnecessarily terse.
But often also less error-prone. YMMV.
> I would have wrote the example like this:
>
> </script>
> class Person {
> constructor(name, surName) {
> this.name = name;
> this.surName = surName
> }
> }
>
> var people = [
> new Person(Brendan", "Eich"),
> new Person("Alan","Kay"),
> new Person("Robert", "Carlyle")
> ]
Names starting with a capital letter should be reserved for constructors,
classes and constants That is, “People”, “Name”, and “Surname” should all
be lowercase here.
Using the same pattern as you used for “tracks”, one can set up the data and
have the custom instances without repeating oneself (ES 2015+):
people = people.map((obj) => new Person(obj.name, obj.surname));
or, more backwards-compatible (ES Ed. 5+):
people = people.map(function (obj) {
return new Person(obj.name, obj.surname);
});
Or, most backwards-compatible (all):
for (var i = people.length; i--;)
{
var obj = people[i];
people[i] = new Person(obj.name, obj.surname);
};
If the class/type has a default constructor (and this is one example that
show that it is a good idea to have one), and provides means to set
individual properties, then this can be even simpler. For example:
people = people.map((obj) => {
var person = new Person();
Object.assign(person, obj);
});
It is also a good idea to have a constructor that in addition to positional
arguments accepts an initializer object as first and only argument.
people = people.map((obj) => new Person(obj));
Such a constructor is particularly useful with JSON.parse(json, reviver),
and in general it is a good idea if a constructor can be called as a
function for type conversion (like type casting). But apparently this is
not possible with ECMAScript classes:
class Person
{
constructor (...args)
{
if (!(this instanceof Person)) return new Person(...args);
/* initialize */
}
}
/* TypeError: Class constructor Person cannot be invoked without 'new' */
Person()
This works:
function Person (...args)
{
/*
* For backwards compatibility JSX:object.js introduces
* Function.prototype.construct(), and I am also thinking about
* adding Function.prototype.toFactory() for DRY.
*/
if (!(this instanceof Person)) return new Person(...args);
/* initialize */
}
/* > Person {} */
Person()
BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Mark-" <nospam@mapson.xyz> |
|---|---|
| Date | 2018-01-19 04:03 +0000 |
| Message-ID | <p3rqms$10d7$1@gioia.aioe.org> |
| In reply to | #34596 |
Thomas 'PointedEars' Lahn wrote: > Names starting with a capital letter should be reserved for > constructors, classes and constants That is, “People”, “Name”, and > “Surname” should all be lowercase here. Poppycock.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 20:06 -0800 |
| Message-ID | <4816b388-10b7-445b-ae2f-040cef723041@googlegroups.com> |
| In reply to | #34596 |
Den fredag 19 januari 2018 kl. 04:56:09 UTC+1 skrev Thomas 'PointedEars' Lahn:
> Michael Haufe (TNO) wrote:
>
> > Jonas Thörnvall wrote:
> >> var People = [
> >> {Name: "Name", Surname: "Surname"},
> >> {Name:"AAA", Surname:"ZZZ"},
> >> {Name: "Name", Surname: "AAA"}
> >> ];
> >> I guess people is an array holding three indexes above?
> >> The properties of people is Name and Surname
> >
> > JavaScript developers have a tendency to "golf" [1] their code just like
> > Perl programmers. Which can make things unnecessarily terse.
>
> But often also less error-prone. YMMV.
>
> > I would have wrote the example like this:
> >
> > </script>
> > class Person {
> > constructor(name, surName) {
> > this.name = name;
> > this.surName = surName
> > }
> > }
> >
> > var people = [
> > new Person(Brendan", "Eich"),
> > new Person("Alan","Kay"),
> > new Person("Robert", "Carlyle")
> > ]
>
> Names starting with a capital letter should be reserved for constructors,
> classes and constants That is, “People”, “Name”, and “Surname” should all
> be lowercase here.
>
> Using the same pattern as you used for “tracks”, one can set up the data and
> have the custom instances without repeating oneself (ES 2015+):
>
> people = people.map((obj) => new Person(obj.name, obj.surname));
>
> or, more backwards-compatible (ES Ed. 5+):
>
> people = people.map(function (obj) {
> return new Person(obj.name, obj.surname);
> });
>
> Or, most backwards-compatible (all):
>
> for (var i = people.length; i--;)
> {
> var obj = people[i];
> people[i] = new Person(obj.name, obj.surname);
> };
>
> If the class/type has a default constructor (and this is one example that
> show that it is a good idea to have one), and provides means to set
> individual properties, then this can be even simpler. For example:
>
> people = people.map((obj) => {
> var person = new Person();
> Object.assign(person, obj);
> });
>
> It is also a good idea to have a constructor that in addition to positional
> arguments accepts an initializer object as first and only argument.
>
> people = people.map((obj) => new Person(obj));
>
> Such a constructor is particularly useful with JSON.parse(json, reviver),
> and in general it is a good idea if a constructor can be called as a
> function for type conversion (like type casting). But apparently this is
> not possible with ECMAScript classes:
>
> class Person
> {
> constructor (...args)
> {
> if (!(this instanceof Person)) return new Person(...args);
>
> /* initialize */
> }
> }
>
> /* TypeError: Class constructor Person cannot be invoked without 'new' */
> Person()
>
> This works:
>
> function Person (...args)
> {
> /*
> * For backwards compatibility JSX:object.js introduces
> * Function.prototype.construct(), and I am also thinking about
> * adding Function.prototype.toFactory() for DRY.
> */
> if (!(this instanceof Person)) return new Person(...args);
>
> /* initialize */
> }
>
> /* > Person {} */
> Person()
>
> BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
>
> --
> PointedEars
> FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
I like the old version Thomas
for (var i = people.length; i--;)
{
var obj = people[i];
people[i] = new Person(obj.name, obj.surname);
};
But if Person was initself a property of adress would i then write as below
to create a new person object on the adress. It is the syntax that escapes me.
for (var i = people.length; i--;)
{
var obj = people[i];
residence[x].people[i] = new Person(obj.name, obj.surname);
};
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 20:30 -0800 |
| Message-ID | <c856e5d4-c557-49a1-8b12-799b79a36252@googlegroups.com> |
| In reply to | #34598 |
Den fredag 19 januari 2018 kl. 05:06:51 UTC+1 skrev Jonas Thörnvall:
> Den fredag 19 januari 2018 kl. 04:56:09 UTC+1 skrev Thomas 'PointedEars' Lahn:
> > Michael Haufe (TNO) wrote:
> >
> > > Jonas Thörnvall wrote:
> > >> var People = [
> > >> {Name: "Name", Surname: "Surname"},
> > >> {Name:"AAA", Surname:"ZZZ"},
> > >> {Name: "Name", Surname: "AAA"}
> > >> ];
> > >> I guess people is an array holding three indexes above?
> > >> The properties of people is Name and Surname
> > >
> > > JavaScript developers have a tendency to "golf" [1] their code just like
> > > Perl programmers. Which can make things unnecessarily terse.
> >
> > But often also less error-prone. YMMV.
> >
> > > I would have wrote the example like this:
> > >
> > > </script>
> > > class Person {
> > > constructor(name, surName) {
> > > this.name = name;
> > > this.surName = surName
> > > }
> > > }
> > >
> > > var people = [
> > > new Person(Brendan", "Eich"),
> > > new Person("Alan","Kay"),
> > > new Person("Robert", "Carlyle")
> > > ]
> >
> > Names starting with a capital letter should be reserved for constructors,
> > classes and constants That is, “People”, “Name”, and “Surname” should all
> > be lowercase here.
> >
> > Using the same pattern as you used for “tracks”, one can set up the data and
> > have the custom instances without repeating oneself (ES 2015+):
> >
> > people = people.map((obj) => new Person(obj.name, obj.surname));
> >
> > or, more backwards-compatible (ES Ed. 5+):
> >
> > people = people.map(function (obj) {
> > return new Person(obj.name, obj.surname);
> > });
> >
> > Or, most backwards-compatible (all):
> >
> > for (var i = people.length; i--;)
> > {
> > var obj = people[i];
> > people[i] = new Person(obj.name, obj.surname);
> > };
> >
> > If the class/type has a default constructor (and this is one example that
> > show that it is a good idea to have one), and provides means to set
> > individual properties, then this can be even simpler. For example:
> >
> > people = people.map((obj) => {
> > var person = new Person();
> > Object.assign(person, obj);
> > });
> >
> > It is also a good idea to have a constructor that in addition to positional
> > arguments accepts an initializer object as first and only argument.
> >
> > people = people.map((obj) => new Person(obj));
> >
> > Such a constructor is particularly useful with JSON.parse(json, reviver),
> > and in general it is a good idea if a constructor can be called as a
> > function for type conversion (like type casting). But apparently this is
> > not possible with ECMAScript classes:
> >
> > class Person
> > {
> > constructor (...args)
> > {
> > if (!(this instanceof Person)) return new Person(...args);
> >
> > /* initialize */
> > }
> > }
> >
> > /* TypeError: Class constructor Person cannot be invoked without 'new' */
> > Person()
> >
> > This works:
> >
> > function Person (...args)
> > {
> > /*
> > * For backwards compatibility JSX:object.js introduces
> > * Function.prototype.construct(), and I am also thinking about
> > * adding Function.prototype.toFactory() for DRY.
> > */
> > if (!(this instanceof Person)) return new Person(...args);
> >
> > /* initialize */
> > }
> >
> > /* > Person {} */
> > Person()
> >
> > BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
> >
> > --
> > PointedEars
> > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
>
> I like the old version Thomas
> for (var i = people.length; i--;)
> {
> var obj = people[i];
> people[i] = new Person(obj.name, obj.surname);
> };
>
> But if Person was initself a property of adress would i then write as below
> to create a new person object on the adress. It is the syntax that escapes me.
>
> for (var i = people.length; i--;)
> {
> var obj = people[i];
> residence[x].people[i] = new Person(obj.name, obj.surname);
> };
I have problem to find example complex enough to really translate to my problem.
So let my give an analogy to my object.
A regional income database, store adresses, on each adress live many people. Each of these people have properties fortune, income, expenditures.
I do understand what you write on those simple objects, but i cannot elevate the knowledge to my problem. Because it is layered. If you show me this i probably can figure it out for any "structure" / prototype i need to create.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-18 20:49 -0800 |
| Message-ID | <9c28fb0e-5359-4960-a133-24a65706290b@googlegroups.com> |
| In reply to | #34598 |
Den fredag 19 januari 2018 kl. 05:06:51 UTC+1 skrev Jonas Thörnvall:
> Den fredag 19 januari 2018 kl. 04:56:09 UTC+1 skrev Thomas 'PointedEars' Lahn:
> > Michael Haufe (TNO) wrote:
> >
> > > Jonas Thörnvall wrote:
> > >> var People = [
> > >> {Name: "Name", Surname: "Surname"},
> > >> {Name:"AAA", Surname:"ZZZ"},
> > >> {Name: "Name", Surname: "AAA"}
> > >> ];
> > >> I guess people is an array holding three indexes above?
> > >> The properties of people is Name and Surname
> > >
> > > JavaScript developers have a tendency to "golf" [1] their code just like
> > > Perl programmers. Which can make things unnecessarily terse.
> >
> > But often also less error-prone. YMMV.
> >
> > > I would have wrote the example like this:
> > >
> > > </script>
> > > class Person {
> > > constructor(name, surName) {
> > > this.name = name;
> > > this.surName = surName
> > > }
> > > }
> > >
> > > var people = [
> > > new Person(Brendan", "Eich"),
> > > new Person("Alan","Kay"),
> > > new Person("Robert", "Carlyle")
> > > ]
> >
> > Names starting with a capital letter should be reserved for constructors,
> > classes and constants That is, “People”, “Name”, and “Surname” should all
> > be lowercase here.
> >
> > Using the same pattern as you used for “tracks”, one can set up the data and
> > have the custom instances without repeating oneself (ES 2015+):
> >
> > people = people.map((obj) => new Person(obj.name, obj.surname));
> >
> > or, more backwards-compatible (ES Ed. 5+):
> >
> > people = people.map(function (obj) {
> > return new Person(obj.name, obj.surname);
> > });
> >
> > Or, most backwards-compatible (all):
> >
> > for (var i = people.length; i--;)
> > {
> > var obj = people[i];
> > people[i] = new Person(obj.name, obj.surname);
> > };
> >
> > If the class/type has a default constructor (and this is one example that
> > show that it is a good idea to have one), and provides means to set
> > individual properties, then this can be even simpler. For example:
> >
> > people = people.map((obj) => {
> > var person = new Person();
> > Object.assign(person, obj);
> > });
> >
> > It is also a good idea to have a constructor that in addition to positional
> > arguments accepts an initializer object as first and only argument.
> >
> > people = people.map((obj) => new Person(obj));
> >
> > Such a constructor is particularly useful with JSON.parse(json, reviver),
> > and in general it is a good idea if a constructor can be called as a
> > function for type conversion (like type casting). But apparently this is
> > not possible with ECMAScript classes:
> >
> > class Person
> > {
> > constructor (...args)
> > {
> > if (!(this instanceof Person)) return new Person(...args);
> >
> > /* initialize */
> > }
> > }
> >
> > /* TypeError: Class constructor Person cannot be invoked without 'new' */
> > Person()
> >
> > This works:
> >
> > function Person (...args)
> > {
> > /*
> > * For backwards compatibility JSX:object.js introduces
> > * Function.prototype.construct(), and I am also thinking about
> > * adding Function.prototype.toFactory() for DRY.
> > */
> > if (!(this instanceof Person)) return new Person(...args);
> >
> > /* initialize */
> > }
> >
> > /* > Person {} */
> > Person()
> >
> > BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
> >
> > --
> > PointedEars
> > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
>
> I like the old version Thomas
> for (var i = people.length; i--;)
> {
> var obj = people[i];
> people[i] = new Person(obj.name, obj.surname);
> };
>
> But if Person was initself a property of adress would i then write as below
> to create a new person object on the adress. It is the syntax that escapes me.
>
> for (var i = people.length; i--;)
> {
> var obj = people[i];
> residence[x].people[i] = new Person(obj.name, obj.surname);
> };
Lets skip the objects prototypes and take it the easy way.
Does not this code create 100 track "objects?" with 5 properties, but one of the properties is a "object?" in its own midimessage that has its own properties?
Right or wrong, that is how i interpreate the code and it pass so "is something".
However i am unable to pass values, "because i suspect just a with the track the messages must be created.
Right or wrong?
This does not work
track[tracknr].midimessage[x].time=clock;
Uncaught TypeError: Cannot set property 'time' of undefined
So the message object do not exist on the track, SO HOW CAN I MAKE ONE???
It seem easier **TO SOLVE THIS** problem then to overhaul all the code and start make class objects and prototypes, when there is no examples given complex enought to match my prefered storage structure.
function makeTrack()
{
for (var m = 0; m < 101; m ++ )
{
track[m] ={
outport:[],
portname : [],
midichannel:[],
program:[],
midimessage:[{time:0,data0:0,data1:0,data2:0}]
};
}
defaultTrackValues();
makeMessages();
return track;
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-19 00:12 -0800 |
| Message-ID | <dc333c3d-1e0b-499f-b85f-44e34cef5d85@googlegroups.com> |
| In reply to | #34600 |
Den fredag 19 januari 2018 kl. 05:49:51 UTC+1 skrev Jonas Thörnvall:
> Den fredag 19 januari 2018 kl. 05:06:51 UTC+1 skrev Jonas Thörnvall:
> > Den fredag 19 januari 2018 kl. 04:56:09 UTC+1 skrev Thomas 'PointedEars' Lahn:
> > > Michael Haufe (TNO) wrote:
> > >
> > > > Jonas Thörnvall wrote:
> > > >> var People = [
> > > >> {Name: "Name", Surname: "Surname"},
> > > >> {Name:"AAA", Surname:"ZZZ"},
> > > >> {Name: "Name", Surname: "AAA"}
> > > >> ];
> > > >> I guess people is an array holding three indexes above?
> > > >> The properties of people is Name and Surname
> > > >
> > > > JavaScript developers have a tendency to "golf" [1] their code just like
> > > > Perl programmers. Which can make things unnecessarily terse.
> > >
> > > But often also less error-prone. YMMV.
> > >
> > > > I would have wrote the example like this:
> > > >
> > > > </script>
> > > > class Person {
> > > > constructor(name, surName) {
> > > > this.name = name;
> > > > this.surName = surName
> > > > }
> > > > }
> > > >
> > > > var people = [
> > > > new Person(Brendan", "Eich"),
> > > > new Person("Alan","Kay"),
> > > > new Person("Robert", "Carlyle")
> > > > ]
> > >
> > > Names starting with a capital letter should be reserved for constructors,
> > > classes and constants That is, “People”, “Name”, and “Surname” should all
> > > be lowercase here.
> > >
> > > Using the same pattern as you used for “tracks”, one can set up the data and
> > > have the custom instances without repeating oneself (ES 2015+):
> > >
> > > people = people.map((obj) => new Person(obj.name, obj.surname));
> > >
> > > or, more backwards-compatible (ES Ed. 5+):
> > >
> > > people = people.map(function (obj) {
> > > return new Person(obj.name, obj.surname);
> > > });
> > >
> > > Or, most backwards-compatible (all):
> > >
> > > for (var i = people.length; i--;)
> > > {
> > > var obj = people[i];
> > > people[i] = new Person(obj.name, obj.surname);
> > > };
> > >
> > > If the class/type has a default constructor (and this is one example that
> > > show that it is a good idea to have one), and provides means to set
> > > individual properties, then this can be even simpler. For example:
> > >
> > > people = people.map((obj) => {
> > > var person = new Person();
> > > Object.assign(person, obj);
> > > });
> > >
> > > It is also a good idea to have a constructor that in addition to positional
> > > arguments accepts an initializer object as first and only argument.
> > >
> > > people = people.map((obj) => new Person(obj));
> > >
> > > Such a constructor is particularly useful with JSON.parse(json, reviver),
> > > and in general it is a good idea if a constructor can be called as a
> > > function for type conversion (like type casting). But apparently this is
> > > not possible with ECMAScript classes:
> > >
> > > class Person
> > > {
> > > constructor (...args)
> > > {
> > > if (!(this instanceof Person)) return new Person(...args);
> > >
> > > /* initialize */
> > > }
> > > }
> > >
> > > /* TypeError: Class constructor Person cannot be invoked without 'new' */
> > > Person()
> > >
> > > This works:
> > >
> > > function Person (...args)
> > > {
> > > /*
> > > * For backwards compatibility JSX:object.js introduces
> > > * Function.prototype.construct(), and I am also thinking about
> > > * adding Function.prototype.toFactory() for DRY.
> > > */
> > > if (!(this instanceof Person)) return new Person(...args);
> > >
> > > /* initialize */
> > > }
> > >
> > > /* > Person {} */
> > > Person()
> > >
> > > BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
> > >
> > > --
> > > PointedEars
> > > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> > > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> > > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
> >
> > I like the old version Thomas
> > for (var i = people.length; i--;)
> > {
> > var obj = people[i];
> > people[i] = new Person(obj.name, obj.surname);
> > };
> >
> > But if Person was initself a property of adress would i then write as below
> > to create a new person object on the adress. It is the syntax that escapes me.
> >
> > for (var i = people.length; i--;)
> > {
> > var obj = people[i];
> > residence[x].people[i] = new Person(obj.name, obj.surname);
> > };
>
> Lets skip the objects prototypes and take it the easy way.
> Does not this code create 100 track "objects?" with 5 properties, but one of the properties is a "object?" in its own midimessage that has its own properties?
>
> Right or wrong, that is how i interpreate the code and it pass so "is something".
>
> However i am unable to pass values, "because i suspect just a with the track the messages must be created.
>
> Right or wrong?
> This does not work
> track[tracknr].midimessage[x].time=clock;
> Uncaught TypeError: Cannot set property 'time' of undefined
>
> So the message object do not exist on the track, SO HOW CAN I MAKE ONE???
> It seem easier **TO SOLVE THIS** problem then to overhaul all the code and start make class objects and prototypes, when there is no examples given complex enought to match my prefered storage structure.
>
> function makeTrack()
> {
> for (var m = 0; m < 101; m ++ )
> {
> track[m] ={
> outport:[],
> portname : [],
> midichannel:[],
> program:[],
> midimessage:[{time:0,data0:0,data1:0,data2:0}]
> };
>
> }
> defaultTrackValues();
> makeMessages();
> return track;
> }
I just do not get it...
I realised that the structure i did not quite understand so i though i go for something easier. I break out the message. But i still get same error message?
It is basicly the same as creation of tracks, and i have no problem assig values to them.
function record(message){
clock=clock+rs;
midievent++;
midimessage[1].time=clock;
midimessage[1].data0= message.data[0];
midimessage[1].data1= message.data[1];
midimessage[1].data2= message.data[2];
x++;
console.log("Track="+tracknr);
}
function newMessage(n)
{
midimessage[n]={
time:0,
data0:0,
data1:0,
data2:0
};
return midimessage;
}
function makeTrack(){
for (var m=0;m<101;m++){
newTrack(m);
for (var n = 0;n < 10000; n++){
newMessage(n);
}
}
defaultTrack();
}
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-19 02:01 -0800 |
| Message-ID | <2f20c821-2a82-4d9c-888c-c654643ca88b@googlegroups.com> |
| In reply to | #34601 |
Den fredag 19 januari 2018 kl. 09:12:16 UTC+1 skrev Jonas Thörnvall:
> Den fredag 19 januari 2018 kl. 05:49:51 UTC+1 skrev Jonas Thörnvall:
> > Den fredag 19 januari 2018 kl. 05:06:51 UTC+1 skrev Jonas Thörnvall:
> > > Den fredag 19 januari 2018 kl. 04:56:09 UTC+1 skrev Thomas 'PointedEars' Lahn:
> > > > Michael Haufe (TNO) wrote:
> > > >
> > > > > Jonas Thörnvall wrote:
> > > > >> var People = [
> > > > >> {Name: "Name", Surname: "Surname"},
> > > > >> {Name:"AAA", Surname:"ZZZ"},
> > > > >> {Name: "Name", Surname: "AAA"}
> > > > >> ];
> > > > >> I guess people is an array holding three indexes above?
> > > > >> The properties of people is Name and Surname
> > > > >
> > > > > JavaScript developers have a tendency to "golf" [1] their code just like
> > > > > Perl programmers. Which can make things unnecessarily terse.
> > > >
> > > > But often also less error-prone. YMMV.
> > > >
> > > > > I would have wrote the example like this:
> > > > >
> > > > > </script>
> > > > > class Person {
> > > > > constructor(name, surName) {
> > > > > this.name = name;
> > > > > this.surName = surName
> > > > > }
> > > > > }
> > > > >
> > > > > var people = [
> > > > > new Person(Brendan", "Eich"),
> > > > > new Person("Alan","Kay"),
> > > > > new Person("Robert", "Carlyle")
> > > > > ]
> > > >
> > > > Names starting with a capital letter should be reserved for constructors,
> > > > classes and constants That is, “People”, “Name”, and “Surname” should all
> > > > be lowercase here.
> > > >
> > > > Using the same pattern as you used for “tracks”, one can set up the data and
> > > > have the custom instances without repeating oneself (ES 2015+):
> > > >
> > > > people = people.map((obj) => new Person(obj.name, obj.surname));
> > > >
> > > > or, more backwards-compatible (ES Ed. 5+):
> > > >
> > > > people = people.map(function (obj) {
> > > > return new Person(obj.name, obj.surname);
> > > > });
> > > >
> > > > Or, most backwards-compatible (all):
> > > >
> > > > for (var i = people.length; i--;)
> > > > {
> > > > var obj = people[i];
> > > > people[i] = new Person(obj.name, obj.surname);
> > > > };
> > > >
> > > > If the class/type has a default constructor (and this is one example that
> > > > show that it is a good idea to have one), and provides means to set
> > > > individual properties, then this can be even simpler. For example:
> > > >
> > > > people = people.map((obj) => {
> > > > var person = new Person();
> > > > Object.assign(person, obj);
> > > > });
> > > >
> > > > It is also a good idea to have a constructor that in addition to positional
> > > > arguments accepts an initializer object as first and only argument.
> > > >
> > > > people = people.map((obj) => new Person(obj));
> > > >
> > > > Such a constructor is particularly useful with JSON.parse(json, reviver),
> > > > and in general it is a good idea if a constructor can be called as a
> > > > function for type conversion (like type casting). But apparently this is
> > > > not possible with ECMAScript classes:
> > > >
> > > > class Person
> > > > {
> > > > constructor (...args)
> > > > {
> > > > if (!(this instanceof Person)) return new Person(...args);
> > > >
> > > > /* initialize */
> > > > }
> > > > }
> > > >
> > > > /* TypeError: Class constructor Person cannot be invoked without 'new' */
> > > > Person()
> > > >
> > > > This works:
> > > >
> > > > function Person (...args)
> > > > {
> > > > /*
> > > > * For backwards compatibility JSX:object.js introduces
> > > > * Function.prototype.construct(), and I am also thinking about
> > > > * adding Function.prototype.toFactory() for DRY.
> > > > */
> > > > if (!(this instanceof Person)) return new Person(...args);
> > > >
> > > > /* initialize */
> > > > }
> > > >
> > > > /* > Person {} */
> > > > Person()
> > > >
> > > > BTW, one should have read <http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/>.
> > > >
> > > > --
> > > > PointedEars
> > > > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
> > > > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
> > > > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
> > >
> > > I like the old version Thomas
> > > for (var i = people.length; i--;)
> > > {
> > > var obj = people[i];
> > > people[i] = new Person(obj.name, obj.surname);
> > > };
> > >
> > > But if Person was initself a property of adress would i then write as below
> > > to create a new person object on the adress. It is the syntax that escapes me.
> > >
> > > for (var i = people.length; i--;)
> > > {
> > > var obj = people[i];
> > > residence[x].people[i] = new Person(obj.name, obj.surname);
> > > };
> >
> > Lets skip the objects prototypes and take it the easy way.
> > Does not this code create 100 track "objects?" with 5 properties, but one of the properties is a "object?" in its own midimessage that has its own properties?
> >
> > Right or wrong, that is how i interpreate the code and it pass so "is something".
> >
> > However i am unable to pass values, "because i suspect just a with the track the messages must be created.
> >
> > Right or wrong?
> > This does not work
> > track[tracknr].midimessage[x].time=clock;
> > Uncaught TypeError: Cannot set property 'time' of undefined
> >
> > So the message object do not exist on the track, SO HOW CAN I MAKE ONE???
> > It seem easier **TO SOLVE THIS** problem then to overhaul all the code and start make class objects and prototypes, when there is no examples given complex enought to match my prefered storage structure.
> >
> > function makeTrack()
> > {
> > for (var m = 0; m < 101; m ++ )
> > {
> > track[m] ={
> > outport:[],
> > portname : [],
> > midichannel:[],
> > program:[],
> > midimessage:[{time:0,data0:0,data1:0,data2:0}]
> > };
> >
> > }
> > defaultTrackValues();
> > makeMessages();
> > return track;
> > }
>
> I just do not get it...
> I realised that the structure i did not quite understand so i though i go for something easier. I break out the message. But i still get same error message?
> It is basicly the same as creation of tracks, and i have no problem assig values to them.
>
> function record(message){
> clock=clock+rs;
> midievent++;
> midimessage[1].time=clock;
> midimessage[1].data0= message.data[0];
> midimessage[1].data1= message.data[1];
> midimessage[1].data2= message.data[2];
> x++;
> console.log("Track="+tracknr);
> }
>
> function newMessage(n)
> {
> midimessage[n]={
> time:0,
> data0:0,
> data1:0,
> data2:0
> };
> return midimessage;
> }
>
> function makeTrack(){
> for (var m=0;m<101;m++){
> newTrack(m);
> for (var n = 0;n < 10000; n++){
> newMessage(n);
> }
> }
> defaultTrack();
> }
Well i decided to keep my structure and sort the timed messages in three data fields using a routine of my own and skip sort(), because i will not resolve the structure needed. And then i don't have to change anything else.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-01-25 07:49 +0100 |
| Message-ID | <4470561.FAyar4cuLI@PointedEars.de> |
| In reply to | #34598 |
Jonas Thörnvall wrote:
> [full quote]
> […]
> But if Person was initself a property of adress would i then write as
> below to create a new person object on the adress. It is the syntax that
> escapes me.
> […]
Too bad. But that is living testament either to your veracity
or the reliability of the results of IQ tests. [1]
_______
[1] <news:2db62a9d-9048-4ecf-b339-5bcd240ba2a4@googlegroups.com>
<https://groups.google.com/d/msg/comp.lang.javascript/paDy9O_kOdc/di8NO_kbCwAJ>
--
PointedEars
FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix>
<https://github.com/PointedEars> | <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | Jonas Thörnvall <jonas.thornvall@gmail.com> |
|---|---|
| Date | 2018-01-30 01:06 -0800 |
| Message-ID | <223c9b8b-c50e-4280-b691-1f427990cd97@googlegroups.com> |
| In reply to | #34661 |
Den torsdag 25 januari 2018 kl. 07:50:11 UTC+1 skrev Thomas 'PointedEars' Lahn: > Jonas Thörnvall wrote: > > > [full quote] > > […] > > But if Person was initself a property of adress would i then write as > > below to create a new person object on the adress. It is the syntax that > > escapes me. > > […] > > Too bad. But that is living testament either to your veracity > or the reliability of the results of IQ tests. [1] > > _______ > [1] <news:2db62a9d-9048-4ecf-b339-5bcd240ba2a4@googlegroups.com> > <https://groups.google.com/d/msg/comp.lang.javascript/paDy9O_kOdc/di8NO_kbCwAJ> > -- > PointedEars > FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> > <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> > Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail. Well i know you hardly have 120 in IQ that is why you have to walk around with a support cain up your ass, to feel selfimportant i should not say that all ENTP are average IQ there is of course exceptions. But the crutch up your ass that make you anal retentive it will not make you solve any real problems.
[toc] | [prev] | [next] | [standalone]
| From | Thomas 'PointedEars' Lahn <PointedEars@web.de> |
|---|---|
| Date | 2018-01-30 11:01 +0100 |
| Message-ID | <3546515.6gl9K5m1Qe@PointedEars.de> |
| In reply to | #34681 |
</killfile> Jonas Thörnvall wrote: > [self-aggrandizing nonsense] I am glad that I did not waste more than those few lines on you. <killfile> -- PointedEars FAQ: <http://PointedEars.de/faq> | <http://PointedEars.de/es-matrix> <https://github.com/PointedEars> | <http://PointedEars.de/wsvn/> Twitter: @PointedEars2 | Please do not cc me./Bitte keine Kopien per E-Mail.
[toc] | [prev] | [next] | [standalone]
| From | "Mark-" <nospam@mapson.xyz> |
|---|---|
| Date | 2018-01-30 13:37 +0000 |
| Message-ID | <p4psfe$fqm$1@gioia.aioe.org> |
| In reply to | #34683 |
Thomas 'PointedEars' Lahn wrote: > </killfile> > > Jonas Thörnvall wrote: > > > [self-aggrandizing nonsense] > > I am glad that I did not waste more than those few lines on you. > > <killfile> Publicly taking this action (adding a person to a killfile) is very sad, immature and grand standing.
[toc] | [prev] | [next] | [standalone]
| From | John G Harris <niam@jghnorth.org.uk.invalid> |
|---|---|
| Date | 2018-01-30 19:14 +0000 |
| Message-ID | <5ug17d1jcu5jtmgfklcp4hgkujff9qlnv0@4ax.com> |
| In reply to | #34683 |
On Tue, 30 Jan 2018 11:01:13 +0100, Thomas 'PointedEars' Lahn <PointedEars@web.de> wrote: >Jonas Thörnvall wrote: > >> [self-aggrandizing nonsense] Thomas said : > [Thomas tells lies] John, writing in the style of Thomas :-(
[toc] | [prev] | [next] | [standalone]
Page 1 of 2 [1] 2 Next page →
Back to top | Article view | comp.lang.javascript
csiph-web