• python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Facebook Twitter Instagram
Devs Fixed
  • python
  • javascript
  • reactjs
  • sql
  • c#
  • java
Devs Fixed
Home ยป Resolved: How can one call the superclass method from a subclass method and return control to the subclass method for an S4 class?

Resolved: How can one call the superclass method from a subclass method and return control to the subclass method for an S4 class?

0
By Isaac Tonny on 18/06/2022 Issue
Share
Facebook Twitter LinkedIn

Question:

If I make two classes like such:
and some method like such:
How can I write a method foobar for the class SubClass that can call the foobar method for SuperClass and then do some other SubClass specific computation?
The method could look something like this:
and then if I do this:
Of course this is a trivial use-case that can be solved by other approaches, but I think it captures that spirit of what I am trying to do.

Answer:

You need callNextMethod:

setMethod(“foobar”, “SubClass”, function(x) {
callNextMethod()
cat(x@b, “\n”, sep=””)
})
x <- new("SubClass") foobar(x) # A # B [/code]

If you have better answer, please add a comment about this, thank you!

r
Share. Facebook Twitter LinkedIn

Related Posts

Resolved: How to resolve LNK2001 in c++ projects

26/03/2023

Resolved: How to correctly initialize vector of number in Typescript

26/03/2023

Resolved: mysql calculating to get profit or loss from 2 tables ( Purchases and Sales) in FIFO mode

26/03/2023

Leave A Reply

© 2023 DEVSFIX.COM

Type above and press Enter to search. Press Esc to cancel.