Created
May 8, 2014 01:27
-
-
Save float1251/7132225fa319e85639c8 to your computer and use it in GitHub Desktop.
vimscriptでclassっぽいことをやってみる
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
" vimscriptでclassっぽく扱う | |
" dictionaryで頑張る | |
let s:MyClass = {"foo": "foo"} | |
function! s:MyClass.print() dict | |
echo self.foo | |
endfunction | |
" instance作成はcopyで代用 | |
function! s:MyClass.new(text) dict | |
let instance = copy(self) | |
let instance.foo = a:text | |
return instance | |
endfunction | |
call s:MyClass.print() | |
let b = s:MyClass.new("Test") | |
call b.print() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment