我正在使用setMethodS3
包 R.methodsS3 来创建 S3 方法。假设我有两个类,class Parent
和class Child
(R.oo 对象)。 class Child
继承自class Parent
。两者都有方法MyMethod()
。如何从 Child's调用超类MyMethod()
(Parent's ) ?我试过这个$MyMethod(),但它调用了Child'sMyMethod
MyMethod()
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()