Bug Tracker

Opened 10 years ago

Closed 10 years ago

#12605 closed bug (notabug)

html() causes an error with the string object

Reported by: Quozzo Owned by:
Priority: undecided Milestone: None
Component: unfiled Version: 1.8.2
Keywords: Cc:
Blocked by: Blocking:


When returning the string object through a constructor it causes an error when that string object is used within html(), but not text().


Change History (3)

comment:1 Changed 10 years ago by Rick Waldron

Resolution: wontfix
Status: newclosed

jQuery cannot protect you from the effects of modifying the prototypes of built-in objects

comment:2 Changed 10 years ago by dmethvin

Resolution: wontfix
Status: closedreopened

Actually, in this case it's not the modification of the prototype, which is pretty common and does work. The problem is that the method returns this which is not the same as the original string. JavaScript always converts primitive types to objects for the this, so it is converting the primitive Strings into String objects. If you return this.toString() it works fine.


The documentation is pretty clear that we want strings, not string *objects* which are a totally different thing. String objects may work in some APIs but it's largely by luck and not design.

comment:3 Changed 10 years ago by dmethvin

Resolution: notabug
Status: reopenedclosed
Note: See TracTickets for help on using tickets.