Path: csiph.com!aioe.org!news.mixmin.net!news2.arglkargh.de!noris.net!newsfeed.arcor.de!newsspool1.arcor-online.net!news.arcor.de.POSTED!not-for-mail Content-Type: text/plain; charset="ISO-8859-1" Message-ID: <2264524.FRqVoOGUtd@PointedEars.de> From: Thomas 'PointedEars' Lahn Reply-To: Thomas 'PointedEars' Lahn Organization: PointedEars Software (PES) Date: Thu, 01 Mar 2012 22:22:32 +0100 User-Agent: KNode/4.4.11 Content-Transfer-Encoding: 7Bit Subject: Re: Reference to slice of an array Newsgroups: comp.lang.javascript References: <628507ee-ddff-4106-8cdc-f2bf70d9423b@cj6g2000vbb.googlegroups.com> <4f4fcc8d$0$6939$e4fe514c@news2.news.xs4all.nl> Followup-To: comp.lang.javascript MIME-Version: 1.0 Lines: 36 NNTP-Posting-Date: 01 Mar 2012 22:22:33 CET NNTP-Posting-Host: c3e7621f.newsspool1.arcor-online.net X-Trace: DXC=\cZFJ^G4aNCWDmlTRbh@=Iic==]BZ:afN4Fo<]lROoRA<`=YMgDjhgBS6]dJ=QET;ADZm8W4\YJNLb@mF9jNikdE0BlJ@Fn<9UI4 "Archos" schreef in bericht > news:628507ee-ddff-4106-8cdc-f2bf70d9423b@cj6g2000vbb.googlegroups.com... >> How to get a reference to a slice of an array? >> >> var A = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j']; >> var s = A.slice(1, 5); // ["b", "c", "d", "e"] >> >> A[1] = 'B'; >> // s is always goes to have ["b", "c", "d", "e"] >> // but I would want could be got the value throught of a reference >> // so could be got ["B", "c", "d", "e"] > > Define a function ? > A.mySlice = function(){return this.slice(1,5)}; > alert(A.mySlice()); You are missing the point of the question. However, in their question the OP is missing the point as well. Unlike in Java, the result of evaluating "b" is a primitive String value in ECMAScript implementations like JavaScript. That value is only internally converted to a (non-primitive) object (a String instance) when it is used with property accessor syntax. So there can be no reference to the former value. In addition, String values and String instances are immutable. RTFM (and RTFFAQ, where several of them are linked) is obviously an exercise the OP has yet to do. PointedEars -- Anyone who slaps a 'this page is best viewed with Browser X' label on a Web page appears to be yearning for the bad old days, before the Web, when you had very little chance of reading a document written on another computer, another word processor, or another network. -- Tim Berners-Lee