有没有办法用参数列表调用vim函数.我的参数列表来自另一个函数中的可选splat参数,我需要一种方法将这些参数传递给目标函数.
目标函数是,
function! run_hello(cmd, ...)
echo 'run_hello'
echo a:cmd
echo a:000
endfunction
Run Code Online (Sandbox Code Playgroud)
将要调用的函数run_hello
是,
function! hello(...)
call run_hello('foo', the splats here)
endfunction
Run Code Online (Sandbox Code Playgroud)
它将被调用,具有不同的参数.
call hello('lorem', 'ipsum', 'dolor')
Run Code Online (Sandbox Code Playgroud)
我目前正在使用hello(arglist)
并a:000
向前传递列表.但我想知道是否可以调用一个带有列表作为参数的函数,然后成为它的常规参数列表.
像JavaScript的东西,
foo.apply(this, ['a', 'b', 'c']
Run Code Online (Sandbox Code Playgroud)
谢谢.
Ing*_*kat 16
相当于JavaScript的apply()
是call()
Vimscript:
function! hello(...)
call call('run_hello', ['foo'] + a:000)
endfunction
Run Code Online (Sandbox Code Playgroud)
这不是拼写错误:你:call
的名字是函数call()
.