Forums | MacLife
You are not logged in.
#1 2009-02-02 8:01 pm
Does JavaScript have anything equivalent to this?
I come from a strictly BASIC background. Which is a bad thing because BASIC knowledge is pretty much fading away these days.
Does JavaScript have an equivalent to QBASIC's "Type"s?
In QB I would use code like this...
Code:
TYPE SomethingType X as INTEGER Y as INTEGER N as STRING * 10 END TYPE DIM SHARED Something(1 to 100) as SomethingType Something(1).X = 300 Something(1).Y = 300 Something(1).N = "My Name"
It allowed me to keep all associated variables in one place with an easy way to manipulate the data and easy way to figure out their names. It's a Something and I am changing its X value.
Is there an easy way or a way at all to get an equivalent in JS?
Offline
#2 2009-02-02 8:33 pm
Re: Does JavaScript have anything equivalent to this?
Mmm... kindofsortofnotreally.
You can't declare Javascript vars as a specific datatype, but you can test for them using typeof.
As for your TYPE, you could use an object. Something like:
Code:
var SomethingType = function () {
this.x;
this.y;
this.n;
}You could just enumerate everything into an array, like so:
Code:
var Something = array(); for (i=0; i<100; i++) Something[i] = new SomethingType(); Something[1].x = 300; Something[1].y = 300; Something[1].n = "My Name";
Basseq is me, John Whittet.
(Finishing the remainder of the thought expressed in the post has been left as an exercise for the reader.)
Offline
#3 2009-02-03 11:30 am
Re: Does JavaScript have anything equivalent to this?
Brilliant. That works exactly how it should. Thanks again!
Offline
