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: |
Description
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
Resolution: | → wontfix |
---|---|
Status: | new → closed |
comment:2 Changed 10 years ago by
Resolution: | wontfix |
---|---|
Status: | closed → reopened |
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.
http://jsfiddle.net/dmethvin/NNKUN/1/
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
Resolution: | → notabug |
---|---|
Status: | reopened → closed |
jQuery cannot protect you from the effects of modifying the prototypes of built-in objects