JavaScript Equivalent Of PHP __call

前端 未结 5 1365
一生所求
一生所求 2020-12-05 09:55

In PHP you can detect when a method is called even when it doesn\'t exist using the \"magic\" __call function.

public function __call($methodNam         


        
5条回答
  •  粉色の甜心
    2020-12-05 10:26

    No. Due to the way JavaScript works, the equivalent would be like Python's __getattr__/__getitem__, rather than PHP's __call, as it would need to be dealt with when retrieving the attribute rather than when calling it.

    Then, you can look at a question like Python's __getattr__ in Javascript which answers it in that way.

    See also such questions as these:

    • JavaScript's equivalent to PHP's __get() magic method
    • JavaScript getter for all properties

提交回复
热议问题