Closed Bug 1360289 Opened 8 years ago Closed 8 years ago

String.prototype based function throws on using this.valueOf() sometimes

Categories

(Core :: JavaScript Engine, defect)

53 Branch
defect
Not set
normal

Tracking

()

RESOLVED INVALID

People

(Reporter: jmichae3, Unassigned)

Details

User Agent: Mozilla/5.0 (Windows NT 6.1; Win64; x64; rv:53.0) Gecko/20100101 Firefox/53.0 Build ID: 20170413192749 Steps to reproduce: String.prototype.reverse=function() { var s2="",i; for (i=0; i < this.ValueOf().length; i++) { s2+=s[this.ValueOf().length-1-i]; } return s2; } Actual results: TypeError: this.ValueOf is not a function[Learn More] atoi64.js:232:16 Expected results: should have just worked. is this causing problems in your code somewhere maybe?
workaround: String.prototype.reverse=function() { var s2="",i,s=this.valueOf(); for (i=0; i < s.length; i++) { s2+=s[s.length-1-i]; } return s2; }
Component: Untriaged → JavaScript Engine
Product: Firefox → Core
Property names are case-sensitive in JS, and the reverse function incorrectly spells ValueOf with an uppercase V. (Besides, valueOf isn't needed at all here and will likely lead to decreased performance.)
Status: UNCONFIRMED → RESOLVED
Closed: 8 years ago
Resolution: --- → INVALID
You need to log in before you can comment on or make changes to this bug.