Skip to content

Instantly share code, notes, and snippets.

@tyru
Created July 21, 2010 23:59
Show Gist options
  • Save tyru/485347 to your computer and use it in GitHub Desktop.
Save tyru/485347 to your computer and use it in GitHub Desktop.
closure in vim script
function! s:foo(num)
let foo = {'i': a:num}
function foo.funcall() dict
let self.i += 1
return self.i
endfunction
return foo
endfunction
echo s:foo(1).funcall()
let s:clos = s:foo(5)
" 6
echo s:clos.funcall()
" 7
echo s:clos.funcall()
" 8
echo s:clos.funcall()
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment