setMethodS3
パッケージ R.methodsS3 を使用して S3 メソッドを作成しています。2 つのクラスclass Parent
とclass Child
(R.oo オブジェクト) があるとします。 class Child
から継承しclass Parent
ます。両方とも方法がありMyMethod()
ます。Child's からスーパークラスMyMethod()
(Parent's )を呼び出すにはどうすればよいですか? this$MyMethod() を試しましたが、Child のMyMethod
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()