Revision 143996 of substr

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/String/substr
  • Revision title: substr
  • Revision id: 143996
  • Created:
  • Creator: Waldo
  • Is current revision? No
  • Comment

Revision Content

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)

Revision Source

<h3 name="Should_print_change_to_other_name.3F"> Should <code>print</code> change to other name? </h3>
<p>Because <code>print</code> conflicts with <a href="en/DOM/window.print"><code>window.print</code></a> in some browsers, should <code>print</code> change to other name? The following code is a example.:
</p>
<pre class="eval">//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));
</pre>
<p>--<a href="User:Potappo">Potappo</a> 04:39, 16 March 2007 (PDT)
</p>
<dl><dd> 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 <code>print()</code> function is defined; also, it's not a huge jump to do something like <code>var print = alert;</code> to make the examples work.  Also, the use of <code>print</code> is reasonably standard -- Perl, Python, and PHP all have a construct named <code>print</code> that does basically what's done by the hypothetical <code>print</code> function used here -- so I don't see a huge gain from switching to something else. --<a href="User:Waldo">Waldo</a> 12:33, 18 March 2007 (PDT)
</dd></dl>
Revert to this revision