function! Class_Prototype() dict
return self
endfunction
function! Class_Override(...) dict
if a:0 == 0|throw "Invalid Parameter"|endif
let class = copy(self)
let class.__NAME__ = a:1
if type(a:2) == type(class.New)
let class.New = a:2
else
let class.New = self.New
endif
let class.Super = self
return class
endfunction
function! Class_New(...) dict
let instance = copy(self)
call remove(instance, "New")
call remove(instance, "Override")
let instance.Super = self
return instance
endfunction
function! Class_ToString() dict
return self.__NAME__
endfunction
let Object = {
\ "__NAME__" : "Object",
\ "Prototype": function("Class_Prototype"),
\ "Override": function("Class_Override"),
\ "Super": {},
\ "New": function("Class_New"),
\ "ToString": function("Class_ToString")}
function! Human_Sing() dict
echo self.perfix . "は" . self.name . "。" . self.title . "\n"
return self
endfunction
function! Human_New(...) dict
let instance = copy(self)
let instance.perfix = a:1
let instance.name = a:2
let instance.title = a:3
let instance.Sing = function("Human_Sing")
return instance
endfunction
let Human = Object.Override("Human", function("Human_New"))
function! Gian_Boxing(who) dict
echo a:who . "のくせに生意気だぞ!!!\n"
return self
endfunction
let Gian = Human.Override("Gian", {})
let Gian.Boxing = function("Gian_Boxing")
let Dekisugi = Human.Override("Dekisugi", {})
silent! unlet gian
silent! unlet dekisugi
let gian = Gian.New("俺", "ジャイアン", "ガキ大将")
let dekisugi = Dekisugi.New("僕", "出来杉", "優等生")
call dekisugi.Sing()
call gian.Sing().Boxing("のび太").Boxing("スネ夫")
僕は出来杉。優等生
俺はジャイアン。ガキ大将
のび太のくせに生意気だぞ!!!
スネ夫のくせに生意気だぞ!!!
つかわねー!参考文献
JSでthisをそのまま返す関数を作っておくと便利?
PHP で引数をそのまま返す関数を作っておくと便利