rhai/scripts/function_decl4.rhai

13 lines
314 B
JavaScript
Raw Normal View History

2022-01-20 05:06:36 +01:00
// This script defines a function that acts as a method.
2021-06-07 14:15:06 +02:00
// Use 'this' to refer to the object of a method call
fn action(x, y) {
this = this.abs() + x * y; // 'this' can be modified
}
let obj = -40;
obj.action(1, 2); // call 'action' as method
print(`obj should now be 42: ${obj}`);