Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.lang.javascript > #30277
| From | "Christoph M. Becker" <cmbecker69@arcor.de> |
|---|---|
| Newsgroups | comp.lang.javascript |
| Subject | Re: duplicator an array |
| Date | 2016-04-14 19:41 +0200 |
| Organization | solani.org |
| Message-ID | <neokoi$6k3$1@solani.org> (permalink) |
| References | <ea578169-9d58-4249-91b4-e0cbad5a6fd8@googlegroups.com> <nen4e4$ggn$1@dont-email.me> |
On 14.04.2016 at 06:00, Aleksandro wrote:
> On 13/04/16 22:27, JRough wrote:
>
>> Okay, supposing the above works then I thought I would make an anonymous function in the duplicator method. This would make it work the way the problem was first outlined above. The only problem is how do I capture the value of the two arrays?
>>
>>
>> I guess you would do something like Array.prototype.duplicator = (function (){
>> return this.concat(arr.slice(0));
>> })()
>
> Try:
>
> Array.prototype.duplicate = function ()
> {
> this.push.apply(this, this.slice(0))
> }
The usual caveats wrt. augmenting built-in objects apply, though, see
e.g.
<http://peter.michaux.ca/articles/javascript-the-good-parts-built-in-object-augmentation-and-namespacing>.
--
Christoph M. Becker
Back to comp.lang.javascript | Previous | Next — Previous in thread | Next in thread | Find similar | Unroll thread
duplicator an array JRough <janis.rough@gmail.com> - 2016-04-13 18:27 -0700
Re: duplicator an array Aleksandro <aleksandro@gmx.com> - 2016-04-14 01:00 -0300
Re: duplicator an array JRough <janis.rough@gmail.com> - 2016-04-14 09:53 -0700
Re: duplicator an array "Christoph M. Becker" <cmbecker69@arcor.de> - 2016-04-14 19:41 +0200
Re: duplicator an array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-14 22:09 +0200
Re: duplicator an array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2016-04-14 22:23 +0200
Re: duplicator an array Stefan Weiss <krewecherl@gmail.com> - 2016-04-16 14:27 +0200
Re: duplicator an array Joao Rodrigues <jr@none.com> - 2016-04-16 12:01 -0300
Re: duplicator an array Joao Rodrigues <jr@none.com> - 2016-04-16 13:43 -0300
Re: duplicator an array Aleksandro <aleksandro@gmx.com> - 2016-04-16 14:13 -0300
Re: duplicator an array bharat.bandgar009@gmail.com - 2017-05-03 01:33 -0700
csiph-web