polserver/testsuite/escript/classes/doc-sample-05.src
Kevin Eady 0988c17f29 Add classes documentation (#717)
* Add escript guide docs for classes

* Add ClassInstanceRef to objref docs

* Use objref.dot to generate svg
2024-10-10 18:06:04 +02:00

19 lines
487 B
Text

class Person()
function Person( this, name, age )
this.name := name;
this.age := age;
endfunction
function greeting( this )
return $"Hello, my name is {this.name} and I am {this.age} years old.";
endfunction
function rename( this, new_name )
this.name := new_name;
Print( $"Name changed to {this.name}" );
endfunction
endclass
var john := Person( "John", 30 );
john.rename( "Johnny" ); // Method call
Person::rename( john, "Johnny" ); // Function call