mozilla

Revision 143998 of substr

  • Revision slug: Talk:JavaScript/Reference/Global_Objects/String/substr
  • Revision title: substr
  • Revision id: 143998
  • Created:
  • Creator: H3h
  • Is current revision? Yes
  • Comment 57 words added; page display name changed to 'substr'

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)
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)

Describing substr() vs. substring() vs. slice() more comprehensively

It seems to me that the wiki should describe the relationship and similarities between these three string methods, along with advice on which to use when. I think that would involve deprecating or discouraging use of substring(). H3h 15 September 2008

Revision Source

<h3 id="Should_print_change_to_other_name.3F" 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" title="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" title="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" title="User:Waldo">Waldo</a> 12:33, 18 March 2007 (PDT) <dl><dd> Thanks for reply. I understand your idea, and I might think too much, so I don't change <code>print</code> to other name. -- <a href="/User:Potappo" title="User:Potappo">Potappo</a> 06:02, 19 March 2007 (PDT) </dd></dl> </dd></dl>
<h3 id="Describing_substr()_vs._substring()_vs._slice()_more_comprehensively">Describing substr() vs. substring() vs. slice() more comprehensively</h3>
<p>It seems to me that the wiki should describe the relationship and similarities between these three string methods, along with advice on which to use when. I think that would involve deprecating or discouraging use of substring(). <a href="http://developer.mozilla.org/User:H3h" rel="custom">H3h</a> 15 September 2008</p>
Revert to this revision