Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #22587 > unrolled thread

Objects in javascript

Started byjonas.thornvall@gmail.com
First post2014-01-12 23:07 -0800
Last post2014-01-13 14:31 +0100
Articles 9 — 6 participants

Back to article view | Back to comp.lang.javascript


Contents

  Objects in javascript jonas.thornvall@gmail.com - 2014-01-12 23:07 -0800
    Re: Objects in javascript Hans-Georg Michna <hans-georgNoEmailPlease@michna.com> - 2014-01-13 10:11 +0100
    Re: Objects in javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-13 11:42 +0100
      Re: Objects in javascript "se" <se@no-one.here> - 2014-01-13 13:25 +0100
      Re: Objects in javascript jonas.thornvall@gmail.com - 2014-01-15 13:59 -0800
        Re: Objects in javascript "Evertjan." <exxjxw.hannivoort@inter.nl.net> - 2014-01-15 23:28 +0100
          Re: Objects in javascript jonas.thornvall@gmail.com - 2014-01-15 15:02 -0800
    Re: Objects in javascript Christoph Michael Becker <cmbecker69@arcor.de> - 2014-01-13 13:48 +0100
      Re: Objects in javascript Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2014-01-13 14:31 +0100

#22587 — Objects in javascript

Fromjonas.thornvall@gmail.com
Date2014-01-12 23:07 -0800
SubjectObjects in javascript
Message-ID<fe9153d3-cec8-4916-a310-e98b2a145373@googlegroups.com>
Could someone pont me to a link, where one can see howto create, read and write to objects in java.

I have a program that basicly, hook up a number with a color and render colored squares to canvas depending on state of checkboxes and the properties of the number, right now it is very stupid it just render in order of execution so it paint over in sequential order, however it does it in the paint section. So the control of checkboxes and the values is within the render loop. Not that beautiful, and also very time consuming.

Can i create an object in Javascript like a number with color attribute, that is set before i start to render, that i write out in the render loop?

The object really have 7 attributes (number, rect, rsize, rcolor, font, fsize, fcolor)

How would i create such an object and how would i update and read from it?   

[toc] | [next] | [standalone]


#22588

FromHans-Georg Michna <hans-georgNoEmailPlease@michna.com>
Date2014-01-13 10:11 +0100
Message-ID<k4b7d9538anhgcet7ujqclnqkcdiqh765o@4ax.com>
In reply to#22587
On Sun, 12 Jan 2014 23:07:19 -0800 (PST),
jonas.thornvall@gmail.com wrote:

>Could someone pont me to a link, where one can see howto create, read and write to objects in java.
>
>I have a program that basicly, hook up a number with a color and render colored squares to canvas depending on state of checkboxes and the properties of the number, right now it is very stupid it just render in order of execution so it paint over in sequential order, however it does it in the paint section. So the control of checkboxes and the values is within the render loop. Not that beautiful, and also very time consuming.
>
>Can i create an object in Javascript like a number with color attribute, that is set before i start to render, that i write out in the render loop?
>
>The object really have 7 attributes (number, rect, rsize, rcolor, font, fsize, fcolor)
>
>How would i create such an object and how would i update and read from it?   

Simplified example:

var obj = { number: 3, font: "sans-serif" };

var num = obj.number; // Yields 3
var font = obj.font; // Yields "sans-serif"

This is rather elementary JavaScript. I think you should learn
the JavaScript basics first, before asking questions here.

Hans-Georg

[toc] | [prev] | [next] | [standalone]


#22592

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-13 11:42 +0100
Message-ID<XnsA2B477051A388eejj99@194.109.133.133>
In reply to#22587
jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:

> Could someone pont me to a link, where one can see howto create, read
> and write to objects in java. 

Wrong NG.

We know nothing about Java here.

-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22596

From"se" <se@no-one.here>
Date2014-01-13 13:25 +0100
Message-ID<lb0m0a$b52$1@dont-email.me>
In reply to#22592
"Evertjan." <exxjxw.hannivoort@inter.nl.net> skrev i meddelelsen 
news:XnsA2B477051A388eejj99@194.109.133.133...
> jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:
>
>> Could someone pont me to a link, where one can see howto create, read
>> and write to objects in java.
>
> Wrong NG.
>
> We know nothing about Java here.
>
> -- 
> Evertjan.
> The Netherlands.
> (Please change the x'es to dots in my emailaddress)

In fact his asking to point him to some learning sources, clear anough.
This is not an unreasonable asking.
Likewise; it should be clear anough from his posting
"Can i create an object in Javascript"
That it's "javascript" and not "java" that concerns him.

Trapping the OP on his word "java" looks like a deliberate
*regular* effort to be short. 

[toc] | [prev] | [next] | [standalone]


#22630

Fromjonas.thornvall@gmail.com
Date2014-01-15 13:59 -0800
Message-ID<7973890c-de85-4812-9b20-471e82b53925@googlegroups.com>
In reply to#22592
Den måndagen den 13:e januari 2014 kl. 11:42:00 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:
> 
> 
> 
> > Could someone pont me to a link, where one can see howto create, read
> 
> > and write to objects in java. 
> 
> 
> 
> Wrong NG.
> 
> 
> 
> We know nothing about Java here.
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

I have some code that i want to change into object oriented code. 
But i am stuck already at the start, i was Think this would reach the first object in the Array and write out a green rectangle?

Usually when i have a working example, i have no trouble start converting.
So could anyone fix what is wrong in the following, example snippet.

<!DOCTYPE HTML>
<html>
  <head>
    <style>
      body {
        margin: 0px;
        padding: 0px;
      }
    </style>
  </head>
  <body>
    <canvas id="myCanvas" width="578" height="200"></canvas>

<script>

function create_objects() {

var arr = [];
var len = 5;
for (var i = 0; i < len; i++) {
    var obj = {
        number: i,
        fcolor: 'black',
        rheight: 100,
        rwidth: 100,
        rcolor: 'green'
    };
    arr.push(obj);
}
}
      create_objects();
      var canvas = document.getElementById('myCanvas');
      var context = canvas.getContext('2d');
      context.beginPath();
      context.rect(188, 50, 200, 100);
      //context.fillStyle = 'yellow';
      context.fillStyle = arr[1].obj.rcolor;
      context.fill();
      context.lineWidth = 7;
      context.strokeStyle = 'black';
      context.stroke();
    </script>
  </body>
</html>

[toc] | [prev] | [next] | [standalone]


#22632

From"Evertjan." <exxjxw.hannivoort@inter.nl.net>
Date2014-01-15 23:28 +0100
Message-ID<XnsA2B6EED7F7FD9eejj99@194.109.133.133>
In reply to#22630
jonas.thornvall@gmail.com wrote on 15 jan 2014 in comp.lang.javascript:

> Den måndagen den 13:e januari 2014 kl. 11:42:00 UTC+1 skrev Evertjan.:
>> jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:
>> > Could someone pont me to a link, where one can see howto create, read
>> > and write to objects in java. 
>> 
>> Wrong NG.
>> We know nothing about Java here.
> 
> I have some code that i want to change into object oriented code.

You are not responding to the quote above, why then do you quote?
 
> But i am stuck already at the start, i was Think this would reach the
> first object in the Array and write out a green rectangle? 
> 
> Usually when i have a working example, i have no trouble start
> converting. So could anyone fix what is wrong in the following, example
> snippet. 

The console of Chrome shows two consecutive errors:

1 the arr should be var-ed global, not inside the function.

> 
> <!DOCTYPE HTML>
> <html>
>   <head>
>     <style>
>       body {
>         margin: 0px;
>         padding: 0px;
>       }
>     </style>
>   </head>
>   <body>
>     <canvas id="myCanvas" width="578" height="200"></canvas>
> 
> <script>

var arr = [];

> function create_objects() {
> 
//  var arr = []; // not here
> var len = 5;
> for (var i = 0; i < len; i++) {
>     var obj = {
>         number: i,
>         fcolor: 'black',
>         rheight: 100,
>         rwidth: 100,
>         rcolor: 'green'
>     };
>     arr.push(obj);
>}
>}
>       create_objects();
>       var canvas = document.getElementById('myCanvas');
>       var context = canvas.getContext('2d');
>       context.beginPath();
>       context.rect(188, 50, 200, 100);
>       //context.fillStyle = 'yellow';
>       context.fillStyle = arr[1].obj.rcolor;

2 this is nonsense, "obj" does not exist outside the create_objects(),
as you push the content of "obj". The console errros should have given it 
away to you.

do:

context.fillStyle = arr[1].rcolor;



>       context.fill();
>       context.lineWidth = 7;
>       context.strokeStyle = 'black';
>       context.stroke();
>     </script>
>   </body>
> </html>

So next time use the error console. 



-- 
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)

[toc] | [prev] | [next] | [standalone]


#22634

Fromjonas.thornvall@gmail.com
Date2014-01-15 15:02 -0800
Message-ID<7dc50a99-b5b7-4be2-8dd6-68ee3ac85c2e@googlegroups.com>
In reply to#22632
Den onsdagen den 15:e januari 2014 kl. 23:28:45 UTC+1 skrev Evertjan.:
> jonas.thornvall@gmail.com wrote on 15 jan 2014 in comp.lang.javascript:
> 
> 
> 
> > Den m�ndagen den 13:e januari 2014 kl. 11:42:00 UTC+1 skrev Evertjan.:
> 
> >> jonas.thornvall@gmail.com wrote on 13 jan 2014 in comp.lang.javascript:
> 
> >> > Could someone pont me to a link, where one can see howto create, read
> 
> >> > and write to objects in java. 
> 
> >> 
> 
> >> Wrong NG.
> 
> >> We know nothing about Java here.
> 
> > 
> 
> > I have some code that i want to change into object oriented code.
> 
> 
> 
> You are not responding to the quote above, why then do you quote?
> 
>  
> 
> > But i am stuck already at the start, i was Think this would reach the
> 
> > first object in the Array and write out a green rectangle? 
> 
> > 
> 
> > Usually when i have a working example, i have no trouble start
> 
> > converting. So could anyone fix what is wrong in the following, example
> 
> > snippet. 
> 
> 
> 
> The console of Chrome shows two consecutive errors:
> 
> 
> 
> 1 the arr should be var-ed global, not inside the function.
> 
> 
> 
> > 
> 
> > <!DOCTYPE HTML>
> 
> > <html>
> 
> >   <head>
> 
> >     <style>
> 
> >       body {
> 
> >         margin: 0px;
> 
> >         padding: 0px;
> 
> >       }
> 
> >     </style>
> 
> >   </head>
> 
> >   <body>
> 
> >     <canvas id="myCanvas" width="578" height="200"></canvas>
> 
> > 
> 
> > <script>
> 
> 
> 
> var arr = [];
> 
> 
> 
> > function create_objects() {
> 
> > 
> 
> //  var arr = []; // not here
> 
> > var len = 5;
> 
> > for (var i = 0; i < len; i++) {
> 
> >     var obj = {
> 
> >         number: i,
> 
> >         fcolor: 'black',
> 
> >         rheight: 100,
> 
> >         rwidth: 100,
> 
> >         rcolor: 'green'
> 
> >     };
> 
> >     arr.push(obj);
> 
> >}
> 
> >}
> 
> >       create_objects();
> 
> >       var canvas = document.getElementById('myCanvas');
> 
> >       var context = canvas.getContext('2d');
> 
> >       context.beginPath();
> 
> >       context.rect(188, 50, 200, 100);
> 
> >       //context.fillStyle = 'yellow';
> 
> >       context.fillStyle = arr[1].obj.rcolor;
> 
> 
> 
> 2 this is nonsense, "obj" does not exist outside the create_objects(),
> 
> as you push the content of "obj". The console errros should have given it 
> 
> away to you.
> 
> 
> 
> do:
> 
> 
> 
> context.fillStyle = arr[1].rcolor;
> 
> 
> 
> 
> 
> 
> 
> >       context.fill();
> 
> >       context.lineWidth = 7;
> 
> >       context.strokeStyle = 'black';
> 
> >       context.stroke();
> 
> >     </script>
> 
> >   </body>
> 
> > </html>
> 
> 
> 
> So next time use the error console. 
> 
> 
> 
> 
> 
> 
> 
> -- 
> 
> Evertjan.
> 
> The Netherlands.
> 
> (Please change the x'es to dots in my emailaddress)

Thank you Evertjan i Think i can go on from here.

[toc] | [prev] | [next] | [standalone]


#22598

FromChristoph Michael Becker <cmbecker69@arcor.de>
Date2014-01-13 13:48 +0100
Message-ID<52d3e092$0$9512$9b4e6d93@newsspool1.arcor-online.net>
In reply to#22587
jonas.thornvall@gmail.com wrote:

> Could someone pont me to a link, where one can see howto create, read
> and write to objects in java.

You may consider reading chapter 2 and 3 of this newsgroup's FAQ[1],
where a lot of resources are pointed out.

[1] <http://pointedears.de/scripts/faq/cljs/#tips>

-- 
Christoph M. Becker

[toc] | [prev] | [next] | [standalone]


#22602

FromThomas 'PointedEars' Lahn <PointedEars@web.de>
Date2014-01-13 14:31 +0100
Message-ID<4567954.NpsAxQBIaO@PointedEars.de>
In reply to#22598
Christoph Michael Becker wrote:

> jonas.thornvall@gmail.com wrote:
>> Could someone pont me to a link, where one can see howto create, read
>> and write to objects in java.
> 
> You may consider reading chapter 2 and 3 of this newsgroup's FAQ[1],
> where a lot of resources are pointed out.
> 
> [1] <http://pointedears.de/scripts/faq/cljs/#tips>

Because the numbering in the FAQ for comp.lang.javascript may be abolished 
(although the corresponding URIs would probably still be valid), please 
refer to its _sections_ by name only.  TIA.

-- 
PointedEars, ed.

Twitter: @PointedEars2
Please do not Cc: me. / Bitte keine Kopien per E-Mail.

[toc] | [prev] | [standalone]


Back to top | Article view | comp.lang.javascript


csiph-web