Answer the question
In order to leave comments, you need to log in
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
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question