vim9script class Counter this.counter = 10 def new() enddef def Up() timer_start(1000, (_time) => { echomsg this.counter this.counter = this.counter + 1 }, { repeat: -1 }) enddef endclass const counter = Counter.new() counter.Up()
:so %Error detected while compiling /tmp/a.vim[17]..function Up[1]..<lambda>68:
line 2:
E1034: Cannot use reserved name this
If I remove this.counter = this.counter + 1 line, no error raised.
It would be great if this keyword can use in lambda function like JavaScript's arrow function this.
Notes:
I know I can use like followings
vim9script class Counter this.counter = 10 def new() enddef def Up() const self = this timer_start(1000, (_time) => { echomsg self.counter self.counter = self.counter + 1 }, { repeat: -1 }) enddef endclass const counter = Counter.new() counter.Up()
Vim9.1474
OS: macOS
Terminal: Terminal.app
value of $TERM: xterm-256color
shell: zsh
No response
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Vimscript "this" is a reserved keyword referring to the current object same to "self" in other programming language. to fix it rename "this" to something else eg self or obj
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Looks like a duplicate of #12076. If you agree you can close this issue.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()
Closed #12336 as completed via 2bd6a09.
—
Reply to this email directly, view it on GitHub.
You are receiving this because you are subscribed to this thread.![]()