diff options
author | Jo-Philipp Wich <jo@mein.io> | 2020-09-15 22:27:12 +0200 |
---|---|---|
committer | Jo-Philipp Wich <jo@mein.io> | 2020-09-15 22:27:12 +0200 |
commit | 8a8f86c54ddf9e5ddd3b06e3067ee61a538c35c0 (patch) | |
tree | b78267d45bfefae62cc48b8c49b9fd402bdddfac | |
parent | 52ac5c3f4b086415dedcff90ddec871f970335cc (diff) |
tests: add test for "this" context
Signed-off-by: Jo-Philipp Wich <jo@mein.io>
-rw-r--r-- | tests/02_runtime/02_this | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/tests/02_runtime/02_this b/tests/02_runtime/02_this new file mode 100644 index 0000000..2c47811 --- /dev/null +++ b/tests/02_runtime/02_this @@ -0,0 +1,28 @@ +The "this" object accesses the current function context. + +-- Expect stdout -- + +-- End -- +true +true +-- Testcase -- +{% + local g = this; + + // Functions not invoked on objects have no this context + function test() { + print(this, "\n"); + return (this === null); + } + + // When invoked, "this" will point to the object containing the function + local o = { + test: function() { + return (this === o); + } + }; + + print(test(), "\n"); + print(o.test(), "\n"); +%} +-- End -- |