Path: csiph.com!news.mixmin.net!weretis.net!feeder1.news.weretis.net!news.solani.org!.POSTED!not-for-mail From: "Christoph M. Becker" Newsgroups: comp.lang.javascript Subject: Re: duplicator an array Date: Thu, 14 Apr 2016 19:41:55 +0200 Organization: solani.org Lines: 26 Message-ID: References: Mime-Version: 1.0 Content-Type: text/plain; charset=utf-8 Content-Transfer-Encoding: 7bit X-Trace: solani.org 1460655698 6787 eJwNxcEBgDAIA8CVSIHgOlDJ/iPofS6d4K1gMlKpM7QJ4/V6uDXe7gVbvFoQmG5d5dFfWu8HFgIRow== (14 Apr 2016 17:41:38 GMT) X-Complaints-To: abuse@news.solani.org NNTP-Posting-Date: Thu, 14 Apr 2016 17:41:38 +0000 (UTC) User-Agent: Mozilla/5.0 (Windows NT 10.0; WOW64; rv:38.0) Gecko/20100101 Thunderbird/38.7.2 X-User-ID: eJwFwYEBwCAIA7CXZlsqnuMY/H/CkqCXa8thxcTMqtMuN4wkpRefKTDnU/tidzLOhZVR+fwRiBBT In-Reply-To: Cancel-Lock: sha1:u5Z5YRn0Ze3Rd3YPT/LIKh5IuM0= X-NNTP-Posting-Host: eJwFwYEBwCAIA7CXdINWzinM/n/CknyxMQwkIp0eV6EJOygAY2rt0rT1CMzrdb5ORtTV4Q8v6xGx Xref: csiph.com comp.lang.javascript:30277 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. . -- Christoph M. Becker