window.toString.call is undefined in IE8

前端 未结 2 1610
独厮守ぢ
独厮守ぢ 2021-01-18 03:38

When you run:

window.toString.call(\"\")

everything\'s fine in FF/CH but in IE8 you get a script error. Investigating a bit more it turned

2条回答
  •  甜味超标
    2021-01-18 04:12

    NickFitz is correct, the toString method on the host object that you are finding is purely so that if you did

    alert(window);

    you would get the text [object]

    All that the javascript method toString() used in your examples would acheive is to make a string from a string so the correct way to do what you are trying is;

    var a =new String ("");
    

    or simply

    var b = "";
    

    or if you really want to be silly;

    var b = "".toString();
    

提交回复
热议问题