Я использую setMethodS3
в пакете R.methodsS3 для создания метода S3.Допустим, у меня есть два класса, class Parent
и class Child
(объект R.oo).class Child
наследуется от class Parent
.У обоих есть метод MyMethod()
.Как мне назвать суперкласс MyMethod()
(родительский MyMethod
) из детского MyMethod()
?Я пробовал этот $ MyMethod (), но он вызывает Child's MyMethod()
Вот сокращенный пример:
library( R.oo )
setConstructorS3( "Parent" , definition =
function()
{
extend( Object() , "Parent" , .stateVar1 = FALSE )
} )
setMethodS3( "MyMethod" , "Parent" , appendVarArgs = FALSE , definition =
function( this , someParam , ... )
{
print( this$.stateVar1 )
print( someParam )
} )
setConstructorS3( "Child" , definition =
function()
{
extend( Parent() , "Child" )
} )
setMethodS3( "MyMethod" , "Child" , appendVarArgs = FALSE , definition =
function( this , someParam , ... )
{
NextMethod( "MyMethod" ) # does not work
this$MyMethod( someParam ) # also does not work
} )
child = Child()
child$MyMethod()