Visit Mozilla.org

Talk:Core JavaScript 1.5 Reference:Global Objects:String:substr

From MDC

[edit] Should print change to other name?

Because print conflicts with window.print in some browsers, should print change to other name? The following code is a example.:

//assumes a echo function is defined.
var str = "abcdefghij";
echo("(1,2): "    + str.substr(1,2));
echo("(-2,2): "   + str.substr(-2,2));
echo("(1): "      + str.substr(1));
echo("(-20, 2): " + str.substr(-20,2));
echo("(20, 2): "  + str.substr(20,2));

--Potappo 04:39, 16 March 2007 (PDT)

I sympathize with the desire, but I don't think it's that huge a deal in practice. I don't think a beginning web developer is likely to assume a print() function is defined; also, it's not a huge jump to do something like var print = alert; to make the examples work. Also, the use of print is reasonably standard -- Perl, Python, and PHP all have a construct named print that does basically what's done by the hypothetical print function used here -- so I don't see a huge gain from switching to something else. --Waldo 12:33, 18 March 2007 (PDT)
Thanks for reply. I understand your idea, and I might think too much, so I don't change print to other name. -- Potappo 06:02, 19 March 2007 (PDT)