String object versus literal - modifying the prototype?
<p>I'm wondering why it seems that adding a method to the prototype of a string literal seems to work, but adding a property does not? I was playing with ideas in relation to <a href="http://stackoverflow.com/questions/3756335/i-am-trying-to-create-a-substr-method-with-a-pointer-is-there-a-more-elegant">this question</a>, and have the following code:</p>

<pre><code>String.prototype._str_index1 = 0;
String.prototype._str_reset = function() {
    this._str_index1 = 0;
};
String.prototype._str_substr = function(len) {
  var ret = this.substr(this._str_index1, len);
  this._str_index1 = this._str_index1 + len;
  return ret;
};

var testString = new String('Loremipsumdolorsitamet,consectetur');
log(testString._str_substr(5));
log(testString._str_substr(4));
​
</code></pre>

<p>This works fine. If however I change the third-last line to:</p>

<pre><code>var testString = 'Loremipsumdolorsitamet,consectetur';
</code></pre>

<p>...it seems that although the method <code>_str_substr</code> exists and is callable on the string literal, the value of the property <code>_str_index1</code> is always 0.</p>

<p>What's up?</p>
