Path: csiph.com!usenet.pasdenom.info!weretis.net!feeder1.news.weretis.net!feeder.erje.net!eu.feeder.erje.net!news.internetdienste.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="UTF-8" Message-ID: <1780396.7rZ4NEZdN2@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 29 Aug 2013 10:42:06 +0200 User-Agent: KNode/4.10.5 Content-Transfer-Encoding: 8Bit X-Face: %i>XG-yXR'\"2P/C_aO%~;2o~?g0pPKmbOw^=NT`tprDEf++D.m7"}HW6.#=U:?2GGctkL,f89@H46O$ASoW&?s}.k+&. MIME-Version: 1.0 Lines: 100 NNTP-Posting-Date: 29 Aug 2013 10:42:09 CEST NNTP-Posting-Host: 857d1df8.newsspool1.arcor-online.net X-Trace: DXC=D7JebZK0T_I[6=1B@oB@@@ic==]BZ:afN4Fo<]lROoRAnkgeX?EC@@@>32E0LlHXPKDZm8W4\YJNLb@mF9jNikdEmA0dJ;NON0OWdeKaLmVnKB X-Complaints-To: usenet-abuse@arcor.de Xref: csiph.com comp.lang.javascript:21094 brettz9@gmail.com wrote: > Per https://gist.github.com/brettz9/6373468 (live at > http://brett-zamir.me/tests/proposal-join-split.html ), I have come across > a need periodically to do joins and use the same glue surrounding the > join. I think it would be handy if one could do: > > ['a', 'b', 'c'].join('|', true); // '|a|b|c|' The prevalent opinion appears to be that boolean arguments to determine the behavior of a function are not a good idea, summarized in “A (highly cohesive) function should do one thing and one thing only.” and GNU's “one tool for one purpose”. I, too, have my share of making this mistake. The more you want to modify the behavior of a function, the more you come you tend to come to the conclusion that a single options argument of the Object type is the better approach. And there comes a point when you want to write a new function for the new behavior instead because you cannot keep the order of the arguments in mind. [My experience shows that functions/methods taking more than a handful (5) *positional* arguments (where order matters) are hard to use because of that, sometimes even more than 3.] There is no good reason why one could not write "|" + ["a", "b", "c"].join("|") + "|" instead, using the standard Array.prototype.join() method. Or, if you are concerned about DRY, var delim = "|"; delim + ["a", "b", "c"].join(delim) + delim > Similarly, with split, one may not require the first and last elements of > the resulting array, so a corresponding ability to easily strip the first > and last elements in the resulting array could also be added. > > '|a|b|c|'.split('|', undefined, true).join(',') // a,b,c Please explain the meaning of the second and third argument passed to your proposed modification of the standard String.prototype.split() method. The same result can be achieved with "|a|b|c|".slice(1, -1).split("|") or "|a|b|c|".split("|").slice(1, -1) so again I do not see the advantage of your proposal here. [.join(",") is optional if the value of this expression is used in string context, as split() returns a reference to an Array instance whose inherited toString() method does what .join(",") does.] I am going to respond to your RegExp.prototype.forEach() suggestion later this week. In general, please - take your suggestions for the next Edition of ECMAScript to the ES Discuss mailing list instead; a so-called “strawman” document may be the outcome: ECMAScript implementations being dynamic languages, we all have extended built-in objects one way or the other before for syntactic sugar. It is not necessarily a good thing to make your use-cases the standard for everyone. The people most likely to give you a proper review with regard to that are reading that mailing list. You want to keep some recommendations in mind when doing this: Also, be aware that the way you are doing it now, the new or changed properties are enumerable (show up in for-in iteration), and you cannot prevent this from happening in implementations of ES Editions earlier than 5 (see Object.defineProperty()). - post using your real name (you may include your nickname for recognition) - avoid posting to Usenet using the borken, spammed Google Groups. Use a locally installed newsreader application instead, like KNode, SeaMonkey, or Thunderbird. - always post the minimum of the relevant code *here*. While a Web reference is useful, this is _not_ the Web, and you cannot assume people going to your Web site, looking up your code there. -- PointedEars Twitter: @PointedEars2 Please do not Cc: me. / Bitte keine Kopien per E-Mail.