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


Groups > comp.lang.javascript > #12330

Re: Reference to slice of an array

Message-ID <2264524.FRqVoOGUtd@PointedEars.de> (permalink)
From Thomas 'PointedEars' Lahn <PointedEars@web.de>
Organization PointedEars Software (PES)
Date 2012-03-01 22:22 +0100
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

Followups directed to: comp.lang.javascript

Show all headers | 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