Skip to main content

Bug Tracker

Side navigation

#12605 closed bug (notabug)

Opened September 25, 2012 03:39PM UTC

Closed September 25, 2012 04:58PM UTC

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

Attachments (0)
Change History (3)

Changed September 25, 2012 03:49PM UTC by rwaldron comment:1

resolution: → wontfix
status: newclosed

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

Changed September 25, 2012 04:58PM UTC by dmethvin comment:2

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.

Changed September 25, 2012 04:58PM UTC by dmethvin comment:3

resolution: → notabug
status: reopenedclosed