Changing the behaviour of the typeof operator in Javascript

前端 未结 4 601
灰色年华
灰色年华 2020-12-20 22:22

I would like to know if there is any way of overriding the behaviour of the typeof operator. Specifically, I want to return \"string\" when the typeof

4条回答
  •  失恋的感觉
    2020-12-20 22:47

    That is impossible. The behaviour of native operators cannot be changed.

    Related links:

    • Why hasn't operator overloading been added to ECMAScript? at quora.com
    • The ES value proxy proposal. It doesn't let you change the existing functionality of typeof, but would enable you to define your own additional types.

提交回复
热议问题