Does valueOf always override toString in javascript?

后端 未结 3 1234
太阳男子
太阳男子 2021-02-20 03:44

Is there any expression where by an object\'s toString method is implicitly called overriding its valueOf method?

In the examples below, valueOf is alw

3条回答
  •  无人及你
    2021-02-20 04:13

    Is there any expression

    Yes. Here's an example that will use toString:

    alert({
        toString: function () {
            return "4";
        },
        valueOf: function () {
            return 6;
        }
    });  // alerts "4"
    

提交回复
热议问题