Skip to content

Commit

Permalink
Update documentation for classes for the modern dialect
Browse files Browse the repository at this point in the history
No implicit fallback to `this` anymore
  • Loading branch information
VasiliyRyabtsev committed Aug 21, 2024
1 parent dcef127 commit 5301177
Showing 1 changed file with 13 additions and 13 deletions.
26 changes: 13 additions & 13 deletions doc/source/reference/language/classes.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}
Expand Down Expand Up @@ -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: ::

Expand All @@ -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 = {}
}
}

Expand All @@ -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
Expand Down Expand Up @@ -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()
}
};

Expand Down Expand Up @@ -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
Expand Down

0 comments on commit 5301177

Please sign in to comment.