473,796 Members | 2,599 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

bug in "splice" using IE6??

Hi -

I'm not sure if I've found a bug with the "splice" function or if I just
need better documentation. Splice doesn't work quite how O'Reilly describes
it (Javascript, 4th edition, Jan 2002, section 9.2.6, pg 144). I'm using
IE6.

var a = new Array( 1,2,3,4,5 );
document.write( a.splice( 0 ) ); // returns "", should return "1,2,3,4,5"

It works when you add the (supposedly optional) second argument. For
example:
a.splice( 0, a.length ); // returns "1,2,3,4,5"

Is this a known bug/feature? Is there a good javascript reference site?

Thanks for the help!

Gary

Here is a short block of code:
<SCRIPT language='javas cript'>

function testSplice() {
var sample = new Array( 1,2,3,4,5 );
parent.document .write( 'doesn\'t work = ' + sample.splice( 0 ) + '<br>' );
parent.document .write( 'works fine = ' + sample.splice( 0, sample.length )
+ '<br>' );
}

</SCRIPT>

<HTML>
<BODY onload="testSpl ice();">
text
</BODY>
</HTML>
Jul 20 '05 #1
6 3346
Gary N. wrote on 26 jan 2004 in comp.lang.javas cript:
I'm not sure if I've found a bug with the "splice" function or if I
just need better documentation. Splice doesn't work quite how
O'Reilly describes it (Javascript, 4th edition, Jan 2002, section
9.2.6, pg 144). I'm using IE6.

var a = new Array( 1,2,3,4,5 );
document.write( a.splice( 0 ) ); // returns "", should return
"1,2,3,4,5"

It works when you add the (supposedly optional) second argument. For
example:
a.splice( 0, a.length ); // returns "1,2,3,4,5"


DeleteCount, the second parameter is REQUIRED.

At least under jScript.

In practice, you could say it is optional, but defaults to 0 (zero) and
nothing is deleted.

It would be very illogical to have the whole array content deleted.
--
Evertjan.
The Netherlands.
(Please change the x'es to dots in my emailaddress)
Jul 20 '05 #2
Lee
Gary N. said:

Hi -

I'm not sure if I've found a bug with the "splice" function or if I just
need better documentation. Splice doesn't work quite how O'Reilly describes
it (Javascript, 4th edition, Jan 2002, section 9.2.6, pg 144). I'm using
IE6.

var a = new Array( 1,2,3,4,5 );
document.write ( a.splice( 0 ) ); // returns "", should return "1,2,3,4,5"

It works when you add the (supposedly optional) second argument.


You need better documentation.
The second argument is not optional:
<http://msdn.microsoft. com/library/default.asp?url =/library/en-us/jscript7/html/jsmthsplice.asp >
<http://devedge.netscap e.com/library/manuals/2000/javascript/1.5/reference/array.html#1193 766>

Jul 20 '05 #3
"Gary N." <ga*********@no spam.intel.com> writes:
I'm not sure if I've found a bug with the "splice" function or if I just
need better documentation. Splice doesn't work quite how O'Reilly describes
it (Javascript, 4th edition, Jan 2002, section 9.2.6, pg 144). I'm using
IE6.
I don't have that book, so I'll go by the ECMAScript standard.
var a = new Array( 1,2,3,4,5 );
document.write( a.splice( 0 ) ); // returns "", should return "1,2,3,4,5"
It returns [] (an array with length 0). That is correct behavior. The
second argument is used to find the *length* of the slice to extract,
using
min(max(ToInteg er( the-second-argument ),0), length-of-rest-of-array)

If omitted, the second arugment is undefined, and ToInteger (an
utility function defined in the specification that is not in the
language) gives 0 on undefined. So, the deleteCount is 0, which is why
you get a zero-length array back.

Are you confuzing the method "splice" with the one called "slice"?
The second, optional, argument of that one will make it extend
to the end of the array.
It works when you add the (supposedly optional) second argument. For
example:
a.splice( 0, a.length ); // returns "1,2,3,4,5"
It *is* optional. If omitted, it is zero (which makes little sense for
splice, but so it goes).
Is this a known bug/feature? Is there a good javascript reference site?


The ECMAScript standard (a little dense, but quite precise).
<URL:http://www.mozilla.org/js/language/E262-3.pdf>
Array.prototype .splice is section 15.4.4.2 and and ToInteger is
section 9.4

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #4
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
It *is* optional.


I take that back. The ECMAScript standard doesn't say what happens if
you call splice with less than two arguments.

If it assumes that the omitted argument is "undefined" , it is as I
said. Browsers seem to do that, except Mozilla, which does what you
expected.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors: <URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html>
'Faith without judgement merely degrades the spirit divine.'
Jul 20 '05 #5
Lasse -

THANK YOU for the JavaScript reference and for looking into splice's
functionality! I'm printing out the manual right now. Other than the
O'Reilly book, I really didn't have a good reference.

Gary
"Lasse Reichstein Nielsen" <lr*@hotpop.com > wrote in message
news:d6******** **@hotpop.com.. .
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:
It *is* optional.
I take that back. The ECMAScript standard doesn't say what happens if
you call splice with less than two arguments.

If it assumes that the omitted argument is "undefined" , it is as I
said. Browsers seem to do that, except Mozilla, which does what you
expected.

/L
--
Lasse Reichstein Nielsen - lr*@hotpop.com
DHTML Death Colors:

<URL:http://www.infimum.dk/HTML/rasterTriangleD OM.html> 'Faith without judgement merely degrades the spirit divine.'

Jul 20 '05 #6
voir la spécification sur :
http://devedge.netscape.com/library/...y.html#1193766

"si deuxième argument est 0 il faut le troisième"
G.Roydor

Lasse Reichstein Nielsen a écrit:
Lasse Reichstein Nielsen <lr*@hotpop.com > writes:

It *is* optional.

I take that back. The ECMAScript standard doesn't say what happens if
you call splice with less than two arguments.

If it assumes that the omitted argument is "undefined" , it is as I
said. Browsers seem to do that, except Mozilla, which does what you
expected.

/L


Jul 20 '05 #7

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

22
4649
by: VK | last post by:
A while ago I proposed to update info in the group FAQ section, but I dropped the discussion using the approach "No matter what color the cat is as long as it still hounts the mice". Over the last month I had enough of extra proof that the cat doesn't hount mice anymore in more and more situations. And the surrent sicretisme among array and hash is the base for it. I summarized all points in this article:...
32
4157
by: James Curran | last post by:
I'd like to make the following proposal for a new feature for the C# language. I have no connection with the C# team at Microsoft. I'm posting it here to gather input to refine it, in an "open Source" manner, and in an attempt to build a ground-swell of support to convince the folks at Microsoft to add it. Proposal: "first:" "last:" sections in a "foreach" block The problem: The foreach statement allows iterating over all the...
59
7524
by: Rico | last post by:
Hello, I have an application that I'm converting to Access 2003 and SQL Server 2005 Express. The application uses extensive use of DAO and the SEEK method on indexes. I'm having an issue when the recordset opens a table. When I write Set rst = db.OpenRecordset("MyTable",dbOpenTable, dbReadOnly) I get an error. I believe it's invalid operation or invalid parameter, I'm
10
25428
by: vunet.us | last post by:
What is the workaround of passign a parameter to any included asp file: <!-- #Include File="file.asp" --> This obviously does not work: <!-- #Include File="file.asp?id=123" --> Thank you
53
2981
by: Aaron Gray | last post by:
I jokingly say this is the late entry :) Okay I have read all the event entry comments from John's Resig's AddEvent comepition blog :- http://ejohn.org/projects/flexible-javascript-events/ and put together the following offering for my LGPL'ed library functions :- function addEvent( el, type, fn, cascade) {
5
13385
matheussousuke
by: matheussousuke | last post by:
Hello, I'm using tiny MCE plugin on my oscommerce and it is inserting my website URL when I use insert image function in the emails. The goal is: Make it send the email with the URL http://mghospedagem.com/images/controlpanel.jpg instead of http://mghospedagem.comhttp://mghospedagem.com/images/controlpanel.jpg As u see, there's the website URL before the image URL.
0
9685
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9531
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10459
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
0
10237
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
1
7553
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6795
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5578
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4120
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2928
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.