In php, at least in my example, magic methods are very often used - at least when defining the main classes from which it will be distributed the most.
The magic methods in php act in a special way from the norm of your usual methods. For example, one of the most common methods in my book for the game will be __construct ()
The construction is performed every time a class is loaded. For example, if you want your class to introduce itself, you can do something like this:
<?php class Person { function __construct($name) { $this->name = $name; $this->introduceYourself(); } public function introduceYourself() { //if $this->name then echo $this->name else echo i dont have name echo $this->name ? "hi my name is " . $this->name : "error i dont have name"; } } $dave = new Person('dave');
Usually you did not pass anything into the construct.
Some others that I come across usually include:
__ call (), which allows you to change the default method called by methods. A good example is redefinition, which allows you to get attribute values ββwhenever you use a method that starts with the word get, or by setting attribute values ββwhenever a method call starts with a set of words.
__ get () is used as an additional loader for class attributes, I do not use, but someone may be interested.
__ set (), used as a reloader for class attributes, I do not use, but someone might be interested.
__ destruct () I also do not use, is called as soon as there are no other references to a specific object or in any order during the shutdown sequence.
Question
Are there any such magic methods inside javascript?
Are there any hidden stones that the new javascript programmer should know, like the ones I described above for php?