473,661 Members | 2,457 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

Calling Array.splice({} ) with no start

Array.splice({} )

What should it do?

I think it should return a new Array with length 0.

Array.splice(ar r, start, deleteCount [, item1 [, item2[,...]]])
http://bclary.com/2004/11/07/#a-15.4.4.12

Example:
Array.splice({} )

Result:
FF3.1
function splice() { [native code] }
Webkit:
undefined
If - start - is passed in, a 0 length array is returned.

Array.prototype .splice.call(0, undefined);
Result: []

The methods that go into calculating the - length - property all call
ToNumber, either through ToUint32, or ToInteger. ToNumber coverts
undefined to NaN, which returns the value back to its caller, either
ToInteger or ToUint32, which converts NaN to +0.
It seems step 4 is not what I expect:
| 4. Call ToInteger(start ).

start is omitted from the argument list, I assume this means start =
undefined.

ToInteger calls ToNumber.
ToInteger:
| 1. Call ToNumber on the input argument.
| 2. If Result(1) is NaN, return +0.
....

ToNumber returns NaN:
| 9.3 ToNumber
| The operator ToNumber converts its argument
| to a value of type Number according to the following table:
|-----------+-----+
| Undefined | NaN |
`....-------+-----+

Back to ToInteger, step 2.
| 2. If Result(1) is NaN, return +0.

Aug 19 '08 #1
18 1824
dhtml wrote:

That would be:
javascript:aler t(Array.prototy pe.isPrototypeO f(
Array.prototype .splice.call({} ) ))

Results:
Opera9.5 mac:
true
FF3.1, Webkit
false

Garrett
Aug 19 '08 #2
On 19 Aug., 07:59, dhtml <dhtmlkitc...@g mail.comwrote:
Array.splice({} )

What should it do?

I think it should return a new Array with length 0.

Array.splice(ar r, start, deleteCount [, item1 [, item2[,...]]])http://bclary.com/2004/11/07/#a-15.4.4.12
I'm only an occasional poster and not expert, but am I falling for a
troll here?

Array.splice({} ) makes semantically absolutely no sense.

a) Splice is the method of an array object, not of the Array global
object.
b) "{}" is an empty object not an "array of the length 0".

So I guess you accually mean [].splice()

However
c) the start and deleteCount parameters are mandatory, so who cares
what the different engines return in such an undefined case?

Robin
Aug 19 '08 #3
On Aug 19, 2:40 pm, Robin Rattay wrote:
On 19 Aug., 07:59, dhtml wrote:
>Array.splice({ })
>What should it do?
>I think it should return a new Array with length 0.
>Array.splice(a rr, start, deleteCount [, item1 [, item2[,...]]])
http://bclary.com/2004/11/07/#a-15.4.4.12

I'm only an occasional poster and not expert, but am
I falling for a troll here?
It would have been easier to tell if the OP had actually made some
(any) point.
Array.splice({} ) makes semantically absolutely no sense.

a) Splice is the method of an array object, not of the
Array global object.
That may just be a misguided use of "Array" to mean any array object.
There are certainly many less ambiguous ways to express that, if it
was the intention.
b) "{}" is an empty object not an "array of the length 0".

So I guess you accually mean [].splice()
More likely - [].slice({}) - else there would have been no point in
mentioning the handling of objects in ToInteger (which without a
modification to Object.prototyp e.toString/valueOf will return numeric
zero).
However
c) the start and deleteCount parameters are mandatory,
No they are not (at least in the sense that omitting them form the
method call will not result in an error and will have a predictable/
specified outcome).
so who cares what the different engines return in such
an undefined case?
If the outcome does not correspond with the specified outcome in any
given implementation then those implementers might care.
Aug 19 '08 #4
Henry wrote:
On Aug 19, 2:40 pm, Robin Rattay wrote:
>On 19 Aug., 07:59, dhtml wrote:
>>Array.splice( {})
What should it do?
I think it should return a new Array with length 0.
Array.splice( arr, start, deleteCount [, item1 [, item2[,...]]])
http://bclary.com/2004/11/07/#a-15.4.4.12
I'm only an occasional poster and not expert, but am
I falling for a troll here?
No, you're trying to answer a question you don't have an answer to and
being mildly insulting in the process. What makes you think I'm a troll?
It would have been easier to tell if the OP had actually made some
(any) point.
Ah, but I asked a question.
>
>Array.splice({ }) makes semantically absolutely no sense.

a) Splice is the method of an array object, not of the
Array global object.
Right, Array.splice is the generic top-level method (and 'Henry' is
likely aware). But that's why I followed up with the
Array.prototype .splice.call sample, which is standard and implemented in
more browsers.
That may just be a misguided use of "Array" to mean any array object.
Nope, just the code I was running in Firefox.
>
>b) "{}" is an empty object not an "array of the length 0".

So I guess you accually mean [].splice()

More likely - [].slice({}) -
No, I meat exactly what I wrote, and if you'd tried it, you might have
noticed that Array.splice({} ) in Firefox, returns the splice function
itself like I wrote. Did you try it?
>However
c) the start and deleteCount parameters are mandatory,

No they are not (at least in the sense that omitting them form the
method call will not result in an error and will have a predictable/
specified outcome).
>so who cares what the different engines return in such
an undefined case?

If the outcome does not correspond with the specified outcome in any
given implementation then those implementers might care.
The question is: "What is the specified output when 'start' is absent?"

Its a somewhat obscure question. I think it should be the array created
in step 1. Webkit and Firefox give different results.

Related thread:
http://groups.google.com/group/comp....8?dmode=source

Regarding step 4 of Array.prototype .splice, if the 'start' argument is
not present, it should be assumed to be undefined, right? This lead
through several more steps, which should result in step 54 returning A.

Garrett
Aug 19 '08 #5
On Aug 19, 6:50 pm, dhtml wrote:
Henry wrote:
>On Aug 19, 2:40 pm, Robin Rattay wrote:
>>On 19 Aug., 07:59, dhtml wrote:
Array.splice ({})
What should it do?
It would have been easier to tell if the OP had actually
made some
(any) point.

Ah, but I asked a question.
If you mean your question was "what should a non-standard language
extension that only exists in a few of implementations do?" then the
answer is "anything it likes, and not necessarily the same thing as
any other non-standard extension that resembles it".
>>Array.splice( {}) makes semantically absolutely no sense.
>>a) Splice is the method of an array object, not of the
Array global object.

Right, Array.splice is the generic top-level method
There is no "the" about it. If there is an - Array.splice - at all
then it is a non-standard language extension.
(and 'Henry' is
likely aware). But that's why I followed up with the
Array.prototype .splice.call sample, which is standard
and implemented in more browsers.
Is it? I did wonder what the point of that follow up was, particularly
as you switched from using an array literal as the argument to splice
to not providing any arguments at all.
>That may just be a misguided use of "Array" to mean any
array object.

Nope, just the code I was running in Firefox.
So it was actually a pointless question; it is generally not viable to
use non-standard language extensions in non-known environment contexts
(as they are unlikely to be either universally or consistently
implemented) and if you have a know environment you can determine the
answer for that context on your own.
>>b) "{}" is an empty object not an "array of the length 0".
>>So I guess you accually mean [].splice()
>More likely - [].slice({}) -

No, I meat exactly what I wrote, and if you'd tried it, you
might have noticed that Array.splice({} ) in Firefox, returns
the splice function itself like I wrote.
You did not write that.
Did you try it?
No, why should I as you made no relevant point?

<snip>
The question is: "What is the specified output when 'start'
is absent?"
<snip>

With - Array.prototype .slice -, an empty array.
With - Array.slice -, ask the people who wrote it.
Aug 19 '08 #6
Henry wrote:
On Aug 19, 6:50 pm, dhtml wrote:
>Henry wrote:
>>On Aug 19, 2:40 pm, Robin Rattay wrote:
On 19 Aug., 07:59, dhtml wrote:
[snip]
>>>b) "{}" is an empty object not an "array of the length 0".
So I guess you accually mean [].splice()
More likely - [].slice({}) -
No, I meat exactly what I wrote, and if you'd tried it, you
might have noticed that Array.splice({} ) in Firefox, returns
the splice function itself like I wrote.

You did not write that.
Anyone can read that first post:
| Example:
| Array.splice({} )
|
|Result:
| FF3.1
| function splice() { [native code] }
|

Firefox 3.1 returning the splice function itself.

The funny thing is, is that if -undefined- is passed in, it works as
expected in Firefox.

javascript:var ap = Array.prototype ;
alert(ap.isProt otypeOf(ap.spli ce.call({})));
FF3.1, Webkit: false
Opera: true

javascript:aler t(ap.isPrototyp eOf(ap.splice.c all({}, undefined)));
FF3.1, Webkit: true
Opera: true

I think Opera is getting this right. I've read through the steps of the
algorithm an the Array created in step 1 should be returned in step 54.
If I'm not mistaken, that's the only Return.

Garrett
Aug 19 '08 #7
dhtml wrote:
Henry wrote:
>On Aug 19, 6:50 pm, dhtml wrote:
>>Henry wrote:
On Aug 19, 2:40 pm, Robin Rattay wrote:
On 19 Aug., 07:59, dhtml wrote:

[snip]
>>>>b) "{}" is an empty object not an "array of the length 0".
So I guess you accually mean [].splice()
More likely - [].slice({}) -
No, I meat exactly what I wrote, and if you'd tried it, you
might have noticed that Array.splice({} ) in Firefox, returns
the splice function itself like I wrote.
You did not write that.

Anyone can read that first post:
| Example:
| Array.splice({} )
|
|Result:
| FF3.1
| function splice() { [native code] }
|

Firefox 3.1 returning the splice function itself.
Firefox 3.1 is already released? Time flies ...
The funny thing is, is that if -undefined- is passed in, it works as
expected in Firefox.

javascript:var ap = Array.prototype ;
alert(ap.isProt otypeOf(ap.spli ce.call({})));
FF3.1, Webkit: false
Opera: true

javascript:aler t(ap.isPrototyp eOf(ap.splice.c all({}, undefined)));
FF3.1, Webkit: true
Opera: true

I think Opera is getting this right. I've read through the steps of the
algorithm an the Array created in step 1 should be returned in step 54.
If I'm not mistaken, that's the only Return.
You don't get it, do you? The language standard makes the first two
arguments of the method *mandatory*, so if an implementation does not error
out if one or both are missing, there is no telling if the return value is
the right or wrong one because there is nothing to base that assessment on.

And Array.splice() is certainly not the same as Array.prototype .splice().
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 19 '08 #8
Thomas 'PointedEars' Lahn wrote:
dhtml wrote:
>Henry wrote:
>>On Aug 19, 6:50 pm, dhtml wrote:
Henry wrote:
On Aug 19, 2:40 pm, Robin Rattay wrote:
>On 19 Aug., 07:59, dhtml wrote:
You don't get it, do you? The language standard makes the first two
arguments of the method *mandatory*,
Apparently I missed the line in the spec that says 'The first two
arguments are necessary.'

About the closest I can get to supporting your claim is:

| When the splice method is called with
| two or more arguments start...
| The following steps are taken:

Which could mean that: The algorithm applies under the conditions of
both -start- and -deleteCount- being present. Or, the sentences could be
taken separately.

The wording isn't clear.

so if an implementation does not error
out if one or both are missing, there is no telling if the return value is
the right or wrong one because there is nothing to base that assessment on.
There's the algorithm for splice. Did you read it?
And Array.splice() is certainly not the same as Array.prototype .splice().
It's actually the same code in the engine, but that's really beside the
point.

Please try to keep this thread focused and not destroy it.

Garrett
>
PointedEars
Aug 19 '08 #9
dhtml wrote:
Thomas 'PointedEars' Lahn wrote:
>You don't get it, do you? The language standard makes the first two
arguments of the method *mandatory*,

Apparently I missed the line in the spec that says 'The first two
arguments are necessary.' [...]
*Obviously*.

| 15.4.4.12 Array.prototype .splice (start, deleteCount [ , item1 [ , item2 [
| , … ] ] ] )

Brackets usually mark optional arguments/parameters, and they do so there.
PointedEars
--
Use any version of Microsoft Frontpage to create your site.
(This won't prevent people from viewing your source, but no one
will want to steal it.)
-- from <http://www.vortex-webdesign.com/help/hidesource.htm>
Aug 20 '08 #10

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

Similar topics

2
2413
by: Tek9_AK | last post by:
I need to find a way to transfer all the values of an array inside a function out of the fuction into another array. IE function splice($filename){ if(file_exists($filename)){ $value=array("0"); // clear the array. $rows=file($filename); // break text file into a rows array for($num=0;$num < count($rows); ++$num){ $column=split(";",$rows); $value=$column;}}
12
55548
by: Sam Collett | last post by:
How do I remove an item with a specified value from an array? i.e. array values 1,2,2,5,7,12,15,21 remove 2 from array would return 1,5,7,12,15,21 (12 and 21 are NOT removed, duplicates are also removed) So far I have (val is value, ar is array, returns new array):
5
6371
by: effendi | last post by:
I wrote a simple script to remove an element of an array but I don't think this is the best way to go about it. I have a list of about five elements seperated by ";" I split the array using array.split(";") command and proceeded to update the elemment by assigning the null value to the arrayindex array=""
15
3318
by: alanbe | last post by:
Greetings I am making a flashcard type application to help me in my TCP/IP protocols test. My instructor will test us periodically on how a device or networking function relates to the OSI layer. EG. bits-layer 1. Any way, I want the quiz to reorder the problems each time I take it. Here is part of the code i did so far for 62 components in the quiz.
2
5212
by: BrianP | last post by:
Hi, I have had to invent a work-around to get past what looks like a JavaScript bug, the malfunctioning Perl-like JavaScript array functions including SPLICE() and UNSHIFT(). I have boiled it down to a very simple test case which can be cut-n-pasted into a .html file and viewed in a browser: ============================================================================
3
6901
by: Newcomsas | last post by:
Hello, I'm trying to solve a problem with JS textbox array without success. I have two buttons in my page: PLUS and MINUS; at every click on PLUS a new textbox named 'dear' is generated. So, if one clicks, say, 3 times the output is something like: dear dear dear
24
4371
by: RyanTaylor | last post by:
I have a final coming up later this week in my beginning Java class and my prof has decided to give us possible Javascript code we may have to write. Problem is, we didn't really cover JS and what we covered was within the last week of the class and all self taught. Our prof gave us an example of a Java method used to remove elements from an array: public void searchProcess() { int outIt=0;
19
6318
by: brasilino | last post by:
Hi Folks: I've been looking (aka googling) around with no success. I need a usability beyond 'pop()' method when removing an Array elements. For example: oName = new Array('Lucas','Brasilino','Silva'); oName.remove('Brasilino'); oName.toString(); // puts out 'Lucas,Silva'
1
2978
by: agendum97 | last post by:
MSDN says splice has the following arguments: arrayObj.splice(start, deleteCount, ]]]) Thus I can insert items into an array using splice. But how do I insert an entire array? For example: var arr1 = ; arr1 = "a"; arr2 = "d";
0
8428
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
8341
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
8851
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
7362
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
6181
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
5650
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();...
1
2760
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
2
1984
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1740
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.