#8182 closed defect (fixed)
Support native String.trim
Reported by: | Adam Peller | Owned by: | Eugene Lazutkin |
---|---|---|---|
Priority: | high | Milestone: | 1.3 |
Component: | String | Version: | 1.2.1 |
Keywords: | Cc: | James Burke | |
Blocked By: | Blocking: |
Description
ECMAScript 3.1 will support String.trim, and FF 3.1 is advertising support for this. Other browsers will follow.
Attachments (1)
Change History (13)
Changed 12 years ago by
Attachment: | trim.patch added |
---|
comment:1 Changed 12 years ago by
Component: | Storage/Flash → String |
---|
comment:2 Changed 12 years ago by
Cc: | James Burke added |
---|---|
Milestone: | 1.3 → 1.4 |
are we sure prototype doesn't add a .trim() method to String.prototype ? For some reason, this doesn't feel right ... are there any subtle differences in FF's .trim() impl and ours?
comment:3 Changed 12 years ago by
I suggest we get it in SRTL. This one's a lot simpler than query. The only possible discrepancy is whether we use the same set of chars -- whitespace should match what RegExp? uses, iirc; not sure about LineSeparator?.
From the ES 3.1 08-11-2008 draft:
15.5.4.20 String.prototype.trim ( ) If this object is not already a string, it is converted to a string. The result is a copy of the string with both leading and trailing white space removed. The definition of white space is the union of WhiteSpace? and LineTerminator?. The result is a string value, not a String object. NOTE The trim function is intentionally generic; it does not require that its this value be a String object. Therefore, it can be transferred to other kinds of objects for use as a method.
I don't see a trim() method in prototype-js (kinda surprising... they must have one?) but I do see one in MS Ajax.net, and sure, other toolkits could define one. So what? I'm sure there are plenty of other places where buggy overrides could mess us up, but this one is important enough to be in a new standard, and the behavior is pretty straight-forward.
comment:5 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
comment:6 Changed 12 years ago by
Milestone: | 1.4 → 1.3 |
---|
comment:7 follow-up: 9 Changed 12 years ago by
Resolution: | fixed |
---|---|
Status: | closed → reopened |
Why not implement it like that (pseudo code):
dojo.trim = String.prototype.trim || function(s){ /* our trim */ };
This way we don't check if the standard trim is available on every single call.
comment:8 Changed 12 years ago by
comment:9 Changed 12 years ago by
Owner: | changed from Adam Peller to Eugene Lazutkin |
---|---|
Status: | reopened → new |
Replying to elazutkin:
Why not implement it like that (pseudo code):
dojo.trim = String.prototype.trim || function(s){ /* our trim */ };This way we don't check if the standard trim is available on every single call.
Good suggestion -- I should have done something like this -- but it seems at a minimum, you need a call (though I'm not sure why offhand) at which point, we start to add some bloat. I worry a bit less about bloating dojo/string.js than base, though I'm starting to think with native methods dojo.string.trim is just bloat itself.
comment:10 Changed 12 years ago by
Resolution: | → fixed |
---|---|
Status: | new → closed |
str.trim is shorter than "trim" in str, but either seems reasonable