diff --git a/doc/source/reference/language/classes.rst b/doc/source/reference/language/classes.rst index 9222169..44828d0 100644 --- a/doc/source/reference/language/classes.rst +++ b/doc/source/reference/language/classes.rst @@ -30,11 +30,11 @@ For instance: :: class Foo { //constructor constructor(a) { - testy = ["stuff",1,2,3,a] + this.testy = ["stuff",1,2,3,a] } //member function function PrintTesty() { - foreach(i,val in testy) { + foreach(i,val in this.testy) { print("idx = "+i+" = "+val) } } @@ -103,7 +103,7 @@ class declaration. The values are copied verbatim, *no cloning is performed* eve .. note:: FOR C# and Java programmers: - Quirrel doesn't clone member's default values nor executes the member declaration for each instance(as C# or java). + Quirrel doesn't clone member's default values nor executes the member declaration for each instance (as C# or java do), just like in Python. So consider this example: :: @@ -122,8 +122,8 @@ class declaration. The values are copied verbatim, *no cloning is performed* eve myarray = null mytable = null constructor() { - myarray = [1,2,3] - mytable = {} + this.myarray = [1,2,3] + this.mytable = {} } } @@ -140,8 +140,8 @@ Constructors, as normal functions, can have variable number of parameters (using class Rect { constructor(w,h) { - width = w - height = h + this.width = w + this.height = h } x = 0 y = 0 @@ -259,7 +259,7 @@ A method of a base class can be explicitly invoked by a method of a derived clas println("I'm the base") } function DoIt() { - DoSomething() + this.DoSomething() } }; @@ -299,14 +299,14 @@ the following example show how to create a class that implements the metamethod class Vector3 { constructor(...) { - if(vargv.len() >= 3) { - x = vargv[0] - y = vargv[1] - z = vargv[2] + if (vargv.len() >= 3) { + this.x = vargv[0] + this.y = vargv[1] + this.z = vargv[2] } } function _add(other) { - return ::Vector3(x+other.x,y+other.y,z+other.z) + return ::Vector3(this.x+other.x, this.y+other.y, this.z+other.z) } x = 0