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


Groups > comp.lang.javascript > #12330

Re: Reference to slice of an array

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> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Reply-To Thomas 'PointedEars' Lahn <cljs@PointedEars.de>
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<HMYlkEJSF
X-Complaints-To usenet-abuse@arcor.de
Xref csiph.com comp.lang.javascript:12330

Followups directed to: comp.lang.javascript

Show key headers only | View raw


Tom de Neef wrote:

> "Archos" <raul.san@sent.com> 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

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


Thread

Reference to slice of an array Archos <raul.san@sent.com> - 2012-03-01 10:42 -0800
  Re: Reference to slice of an array "Tom de Neef" <tdeneef@qolor.nl> - 2012-03-01 20:22 +0100
    Re: Reference to slice of an array Archos <raul.san@sent.com> - 2012-03-01 12:27 -0800
    Re: Reference to slice of an array Thomas 'PointedEars' Lahn <PointedEars@web.de> - 2012-03-01 22:22 +0100
      Re: Reference to slice of an array Scott Sauyet <scott.sauyet@gmail.com> - 2012-03-01 16:24 -0800

csiph-web