Page 1 of 1

Define a Type

Posted: 15 Sep 2011, 19:51
by Shell1850
Jscript can group a group of variables into a type definition.

I created this simple program. It adds 3 numbers.


// create a type

function AddTheseNumbers(first,second,third) {
this.One = first;
this.Two = second;
this.Three = third;
}

function OnComputeOutputs(params)
{
var First = params.ConValue('First');
var Second = params.ConValue('Second');
var Third = params.ConValue('Third');

var NewList = new AddTheseNumbers(First, Second, Third);
var NewAdd = AddNumbers(NewList);

params.ConValue('AddResult') = NewAdd;
}

function AddNumbers(ListofNumbers)
{
return (ListofNumbers.One + ListofNumbers.Two + ListofNumbers.Three);
}

Re: Define a Type

Posted: 16 Sep 2011, 01:25
by froo
Interesting, Shell1850.

I have not looked at the jscript spec, so I'd like to know...
is the word 'this' a keyword in jscript? And if so, is it significant
in relation to how the data structure is instantiated?
In other words, can we use the word: 'that' in place of 'this'?
Or any other variable name for that matter, in your sample code?

Thanks

Froo

Re: Define a Type

Posted: 16 Sep 2011, 01:32
by clintonman
Here's a link to a similar topic.
http://www.webbasedprogramming.com/Spec ... pt/ch4.htm" onclick="window.open(this.href);return false;

Re: Define a Type

Posted: 16 Sep 2011, 01:38
by clintonman
froo wrote:Interesting, Shell1850.

I have not looked at the jscript spec, so I'd like to know...
is the word 'this' a keyword in jscript? And if so, is it significant
in relation to how the data structure is instantiated?
In other words, can we use the word: 'that' in place of 'this'?
Or any other variable name for that matter, in your sample code?

Thanks

Froo
Nope, "this" is a special keyword. From JScript docs, "Refers to the current object""The this keyword is typically used in object constructors to refer to the current object"
I think c or c++ has something similar and I know python also uses it.

Re: Define a Type

Posted: 16 Sep 2011, 02:09
by froo
Thanks clinton.
That's what I was suspecting. C++ uses it.