M
Martin Riat
Hello,
I have some trouble translating a little C++ program I made some years
ago into Javascript. I have defined a class myclass (more complicated
than the example here) and some functions in a similar manner to the
definition of the write function from my example.
Now I need a function that returns a Boolean value and takes 1 or 2
elements from the type myclass as parameters. Somebody can tell me how
I have to write that?
And the I need some functions which takes 1 or more entry parameters
of the type myclass and changes another element from the type myclass.
Something like a = my_function (a, b); How can I do that?
Many thanks for your suggestions.
Kind regards
Martin Riat
-----------------------
var COLUMNS=7;
function myclass () // class definition
{
this.element=Array(COLUMNS+1);
this.maxim;
this.saved=Boolean(true);
this.write=write_my;
// this.compare()=compare_my(); // ????
};
function compare_my(a,b) // does not work ???
// ----------------------------------
// compare 2 elements of myclass
// ----------------------------------
{
return (true);
}
function write_my()
// ----------------------------------
// writes the my_class to screen
// ----------------------------------
{
var counter=COLUMNS;
if (this.saved==true) {document.write("OK-")}
else {document.write("N--")};
for(counter=COLUMNS;counter>0;counter--)
{ document.write(this.element[counter], "<br>"); };
document.write(this.element[0]); // The last one
}
function main ()
{
var test=new myclass();
test.write();
// if (test.equal(test, test)==true) document.write ("Yes")
// else document.write ("No");
return(0);
}
dummy=main();
I have some trouble translating a little C++ program I made some years
ago into Javascript. I have defined a class myclass (more complicated
than the example here) and some functions in a similar manner to the
definition of the write function from my example.
Now I need a function that returns a Boolean value and takes 1 or 2
elements from the type myclass as parameters. Somebody can tell me how
I have to write that?
And the I need some functions which takes 1 or more entry parameters
of the type myclass and changes another element from the type myclass.
Something like a = my_function (a, b); How can I do that?
Many thanks for your suggestions.
Kind regards
Martin Riat
-----------------------
var COLUMNS=7;
function myclass () // class definition
{
this.element=Array(COLUMNS+1);
this.maxim;
this.saved=Boolean(true);
this.write=write_my;
// this.compare()=compare_my(); // ????
};
function compare_my(a,b) // does not work ???
// ----------------------------------
// compare 2 elements of myclass
// ----------------------------------
{
return (true);
}
function write_my()
// ----------------------------------
// writes the my_class to screen
// ----------------------------------
{
var counter=COLUMNS;
if (this.saved==true) {document.write("OK-")}
else {document.write("N--")};
for(counter=COLUMNS;counter>0;counter--)
{ document.write(this.element[counter], "<br>"); };
document.write(this.element[0]); // The last one
}
function main ()
{
var test=new myclass();
test.write();
// if (test.equal(test, test)==true) document.write ("Yes")
// else document.write ("No");
return(0);
}
dummy=main();