B
B
BushaevDenis2019-06-19 19:24:07
JavaScript
BushaevDenis, 2019-06-19 19:24:07

How to create a class in js with auto callable method like __construct() in php?

Let's say I want to make a Module class that will inherit the TestModule child class, which will have a run method that should be automatically called when an instance of the class is created.
In php I would do this:

class Module {
           public function __construct() {
               $this->run();
           }
       }
       
       class TestModule extends Module {
           public function run() {
               echo 'I`m TestModule';
           }
       }
       
       (new TestModule());

Answer the question

In order to leave comments, you need to log in

1 answer(s)
D
DevMan, 2019-06-19
@BushaevDenis

https://developer.mozilla.org/en-US/docs/Web/JavaS...

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question