diff options
author | Bram Moolenaar <Bram@vim.org> | 2020-11-21 13:16:30 +0100 |
---|---|---|
committer | Bram Moolenaar <Bram@vim.org> | 2020-11-21 13:16:30 +0100 |
commit | 4466ad6baa22485abb1147aca3340cced4778a66 (patch) | |
tree | ca11c0216ad16b5ce923f32bebaf116bc0ffc0e9 /README_VIM9.md | |
parent | 2d718267f4b7dcd65261c9f2acd59a6f6bdc8641 (diff) | |
download | vim-git-4466ad6baa22485abb1147aca3340cced4778a66.tar.gz |
Update runtime files
Diffstat (limited to 'README_VIM9.md')
-rw-r--r-- | README_VIM9.md | 18 |
1 files changed, 9 insertions, 9 deletions
diff --git a/README_VIM9.md b/README_VIM9.md index 6c2ee307c..5ee1fdca3 100644 --- a/README_VIM9.md +++ b/README_VIM9.md @@ -159,18 +159,18 @@ thing I have been thinking of is assignments without ":let". I often make that mistake (after writing JavaScript especially). I think it is possible, if we make local variables shadow commands. That should be OK, if you shadow a command you want to use, just rename the variable. -Using "let" and "const" to declare a variable, like in JavaScript and +Using "var" and "const" to declare a variable, like in JavaScript and TypeScript, can work: ``` vim def MyFunction(arg: number): number - let local = 1 - let todo = arg + var local = 1 + var todo = arg const ADD = 88 while todo > 0 local += ADD - --todo + todo -= 1 endwhile return local enddef @@ -192,7 +192,7 @@ function and export it: ``` vim vim9script " Vim9 script syntax used here -let local = 'local variable is not exported, script-local' +var local = 'local variable is not exported, script-local' export def MyFunction() " exported function ... @@ -248,10 +248,10 @@ END return luaeval('sum') endfunc -def VimNew() - let sum = 0 +def VimNew(): number + var sum = 0 for i in range(1, 2999999) - let sum += i + sum += i endfor return sum enddef @@ -277,7 +277,7 @@ echo 'Vim new: ' .. reltimestr(reltime(start)) ``` vim def VimNew(): number - let totallen = 0 + var totallen = 0 for i in range(1, 100000) setline(i, ' ' .. getline(i)) totallen += len(getline(i)) |