- From: Glenn Maynard <glenn@zewt.org>
- Date: Mon, 14 Oct 2013 19:18:07 -0500
- To: Ian Hickson <ian@hixie.ch>
- Cc: whatwg <whatwg@lists.whatwg.org>, Boris Zbarsky <bzbarsky@mit.edu>
On Thu, Oct 10, 2013 at 1:41 PM, Ian Hickson <ian@hixie.ch> wrote: > Leaving aside the issue that "CSS-escape" is more than one operation > depending on what kind of token you're creating, My understanding is that you can do both of them, at least for selector-related escaping, so the author doesn't have to know about the difference. That's based on Simon's earlier mail: On Thu, Oct 10, 2013 at 6:06 AM, Simon Pieters <simonp@opera.com> wrote: > The common case is escaping as ident. An API to escape as ident could be > used for escaping strings, too. In order to not make people think more than > just remembering to escape at all, it might be a good idea to just have one > API to serve both cases, e.g. CSS.escape(foo). > I don't think it's actually as trivial as you think. > > document.getElementById(id) > > ...becomes: > > document.querySelector('#' + escapeCSSIdent(id)) > > ...which is a lot less pretty and understandable, especially when you > consider that many authors are actually coming from: > > document.all[id] > > ...which is briefer than either, and still self-explanatory. > > > I feel this is a case where we're not putting authors first, but are > instead putting spec purity first. > (Nothing about this discussion relates to "spec purity", whatever that means. My argument is that this function is useless legacy, and that proliferating it to DocumentFragment seems to be for consistency's sake only.) I think the example you gave is trivial and perfectly fine, particularly since you need to do the same thing anyway as soon as you're doing anything other than ID lookups or the other couple special cases. I find that happens very quickly, so my code is a lot more readable when I just use querySelector everywhere. But adding another getElementById is probably low cost, so it doesn't bother me that much. -- Glenn Maynard
Received on Tuesday, 15 October 2013 00:18:34 UTC