Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.lang.javascript > #30279

Re: duplicator an array

Path csiph.com!weretis.net!feeder4.news.weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Newsgroups comp.lang.javascript
Subject Re: duplicator an array
Date Thu, 14 Apr 2016 22:23:06 +0200
Organization PointedEars Software (PES)
Lines 42
Message-ID <4431777.cbmzjsbQN4@PointedEars.de> (permalink)
References <ea578169-9d58-4249-91b4-e0cbad5a6fd8@googlegroups.com> <nen4e4$ggn$1@dont-email.me> <neokoi$6k3$1@solani.org> <1593194.mKTEO0Afz8@PointedEars.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
Mime-Version 1.0
Content-Type text/plain; charset="UTF-8"
Content-Transfer-Encoding 8Bit
X-Trace solani.org 1460665387 12162 eJwFwQERADEIAzBLjEJ3LwcY9S/hkwQP5waTkUoR1udWrbe8elHj3C9tYFNeQhId+xCNJ/0tvBH+ (14 Apr 2016 20:23:07 GMT)
X-Complaints-To abuse@news.solani.org
NNTP-Posting-Date Thu, 14 Apr 2016 20:23:07 +0000 (UTC)
User-Agent KNode/4.14.2
X-User-ID eJwFwQkBwDAIA0BLLW8nhwDxL2F3rnGj08LDnM6cQwVlLV+xt6X2oO17A+AqHwZhYOGc3RrSuNQnzJS5P6FDF8o=
Cancel-Lock sha1:WEKUL4iytuMWhGjOH8hLVWRiRu8=
X-NNTP-Posting-Host eJwFwQkBwDAIA0BL0JLA5IzPv4Te4VJZbgQNiy2M9IxlD3ZcVCNWPVJ5zomSXnz5xwUbNXgtWBFp
Xref csiph.com comp.lang.javascript:30279

Show key headers only | View raw


Thomas 'Ingrid' Lahn wrote:

>   try
>   {
>     Object.defineProperty(Array.prototype, "duplicate", {
>       value: function () {
>         return this.concat(this.slice());
>       },
> 
>       /* optional; the default for each attribute is “false” */
>       configurable: true,
>       enumerable: false,
>       writable: true
>     });
>   }
>   catch
 .--------^
 :
(e)

>   {
>     console.warn("Array.prototype.duplicate cannot be (re)configured.");
>   }
> 
> […]
> Otherwise the only safe approach is to augment the instance instead of its
> prototype:
> 
> (function () {
>   var a = [1, 2, 3];
> 
>   a.duplicate = function () {
>     return this.concat(this.slice());
>   };

Or like above.

-- 
PointedEars
FAQ: <http://PointedEars.de/faq> | SVN: <http://PointedEars.de/wsvn/>
Twitter: @PointedEars2 | ES Matrix: <http://PointedEars.de/es-matrix>
Please do not cc me. / Bitte keine Kopien per E-Mail.

Back to comp.lang.javascript | Previous | NextPrevious in thread | Next in thread | Find similar | Unroll thread


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