Calling Array.splice({}) with no start

D

dhtml

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

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.
 
D

dhtml

dhtml wrote:

That would be:
javascript:alert(Array.prototype.isPrototypeOf(
Array.prototype.splice.call({}) ))

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

Garrett
 
R

Robin Rattay

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?

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
 
H

Henry

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?

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.prototype.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.
 
D

dhtml

Henry said:
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.

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?
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).


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.lang.javascript/msg/fa493e719e9ed8b8?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
 
H

Henry

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".
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.
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?

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.
 
D

dhtml

Henry said:
[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.isPrototypeOf(ap.splice.call({})));
FF3.1, Webkit: false
Opera: true

javascript:alert(ap.isPrototypeOf(ap.splice.call({}, 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
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Henry said:
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.isPrototypeOf(ap.splice.call({})));
FF3.1, Webkit: false
Opera: true

javascript:alert(ap.isPrototypeOf(ap.splice.call({}, 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
 
D

dhtml

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
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Thomas said:
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
 
D

dhtml

Thomas said:
dhtml said:
Thomas said:
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.

Usually. But the spec has examples of sections that don't seem to follow
that convention. For example:

What about slice:
15.4.4.10 Array.prototype.slice(start, end)

or sort:
15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The arguments are
optional in all modern (non-beta) implementations.

slice is very commonly used to convert an object to an array, and is
often used with no arguments. For example:

Array.prototype.slice.call(arguments);

There is a general rule established by most (if not all) other methods
that if an argument is missing, it is treated as undefined.

The "optional arguments are bracketed" rule is not mentioned in the
Notational Conventions section, nor is there any text in the document
that says what should happen if an argument is missing.

Garrett
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Thomas said:
dhtml said:
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.

Usually. But the spec has examples of sections that don't seem to follow
that convention. For example:

What about slice:
15.4.4.10 Array.prototype.slice(start, end)

or sort:
15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The arguments are
optional in all modern (non-beta) implementations.

Non sequitur.

In the first case, either you are observing unspecified behavior or the
specification prose has to be considered too imprecise there as the provided
evidence shows.

In the second case, there is "If comparefn is not undefined" and "Otherwise
the following steps are taken." which would indicate that this argument of
this method is optional since according to section 10.1.3 extra formal
parameters have the value `undefined'.

Please do not quote signatures unless you refer to them.


PointedEars
 
D

dhtml

Thomas said:
dhtml said:
Thomas said:
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.
Usually. But the spec has examples of sections that don't seem to follow
that convention. For example:

What about slice:
15.4.4.10 Array.prototype.slice(start, end)

or sort:
15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The arguments are
optional in all modern (non-beta) implementations.

Non sequitur.

Shows that optional arguments are treated as undefined.
In the first case, either you are observing unspecified behavior or the
specification prose has to be considered too imprecise there as the provided
evidence shows.

It is the case that slice treats the unspecified params as undefined.
In the second case, there is "If comparefn is not undefined" and "Otherwise
the following steps are taken." which would indicate that this argument of
this method is optional since according to section 10.1.3 extra formal
parameters have the value `undefined'.

Right. As stated in 10.1.3, if the caller supplies fewer parameters than
formal parameters, the extra parameter variables have the value
undefined. And splice() is a function.

IOW, When an argument is absent, undefined is used as the value. The
only exception I find is FF/Webkit's implentation splice. Both treat
"argument missing" as something different from undefined.

[].splice.call({})
FF3, Webkit both return undefined
Opera 9.5 returns 0 length array.
[].splice.call({},undefined)
FF3, Webkit, Opera 9.5 all return a 0 length array.

Garrett
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Thomas said:
dhtml said:
Thomas 'PointedEars' Lahn wrote:
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.
Usually. But the spec has examples of sections that don't seem to follow
that convention. For example:

What about slice:
15.4.4.10 Array.prototype.slice(start, end)

or sort:
15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The arguments are
optional in all modern (non-beta) implementations.
Non sequitur.

Shows that optional arguments are treated as undefined.

If anything, it shows that that the specification is worded imprecisely.
Which point are you trying to make here? It was never debated that formal
parameters for which no value has been passed are treated as undefined *on
call*, that is what is specified. (Why did you reiterate that anyway?)

But what that means for the underlying algorithm of the method and therefore
for its return value, is an entirely different matter. If the Specification
does not say how an implementation is supposed to behave in such a case, it
is wrong to say that one implementation is correct and another one is not
just because the outcomes differ.
^^^^^^^^^^^
Which part of that did you not get?


PointedEars
 
D

dhtml

Thomas said:
dhtml said:
Thomas said:
dhtml wrote:
Thomas 'PointedEars' Lahn wrote:
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.
Usually. But the spec has examples of sections that don't seem to follow
that convention. For example:

What about slice:
15.4.4.10 Array.prototype.slice(start, end)

or sort:
15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The arguments are
optional in all modern (non-beta) implementations.
Non sequitur.
Shows that optional arguments are treated as undefined.

If anything, it shows that that the specification is worded imprecisely.
Which point are you trying to make here?

Weren't you saying that non-square bracketed arguments were mandatory?

You inferred that 'square brackets means optional'. Then you seemed to
deny the antecedent of that inference with: if a parameter is non-square
bracketed, it is *mandatory* is faulty logic.

1. squares bracket not defined/documented.
2. other methods w/no square brackets around arguments use undefined for
missing arguments.

The square brackets don't have a defined meaning.

It was never debated that formal
parameters for which no value has been passed are treated as undefined *on
call*, that is what is specified. (Why did you reiterate that anyway?)

But what that means for the underlying algorithm of the method and therefore
for its return value, is an entirely different matter. If the Specification
does not say how an implementation is supposed to behave in such a case, it
is wrong to say that one implementation is correct and another one is not
just because the outcomes differ.

It sounds like you're still arguing that the underlying algorithm is
allowed to implement unique behavior when non-square bracketed arguments
are omitted. I don't see any grounds for this argument, in practice, or
in the spec.

It seems most reasonable to go with the behavior that is set forth in
10.1.3. Since implementations do this for non-square bracketed arguments
of all other methods, it is safe to say that it is a rule. The value
undefined should be used for a missing parameter, regardless of square
brackets.

Garrett
 
T

Thomas 'PointedEars' Lahn

dhtml said:
Thomas said:
dhtml said:
Thomas 'PointedEars' Lahn wrote:
dhtml wrote:
Thomas 'PointedEars' Lahn wrote:
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.
Usually. But the spec has examples of sections that don't seem to
follow that convention. For example:

What about slice: 15.4.4.10 Array.prototype.slice(start, end)

or sort: 15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The
arguments are optional in all modern (non-beta) implementations.
Non sequitur.
Shows that optional arguments are treated as undefined.
If anything, it shows that that the specification is worded
imprecisely. Which point are you trying to make here?

Weren't you saying that non-square bracketed arguments were mandatory?

Not so, I did not.
The square brackets don't have a defined meaning.

Yes, they have.
It sounds like you're still arguing that the underlying algorithm is
allowed to implement unique behavior when non-square bracketed arguments
are omitted.

Again, for the intellectually challenged among us: I am arguing instead that
brackets would give an indication as to which arguments are optional and
which are not; however, as the Specification is obviously worded
imprecisely, the Specification prose also counts. If there is nothing in
the prose/algorithm of a method to define what is to be done when certain
arguments are omitted, it is not reasonable to call one return value wrong
and one right. Period.
I don't see any grounds for this argument, in practice, or in the spec.

It seems most reasonable to go with the behavior that is set forth in
10.1.3. Since implementations do this for non-square bracketed arguments
of all other methods, it is safe to say that it is a rule. The value
undefined should be used for a missing parameter, regardless of square
brackets.

Non sequitur. You misunderstood completely what I was saying; given your
other luser-like behavior, maybe on purpose:
[quoting unreferred parts including my signature again]

Score adjusted

PointedEars
 
D

dhtml

Thomas said:
dhtml said:
Thomas said:
dhtml wrote:
Thomas 'PointedEars' Lahn wrote:
dhtml wrote:
Thomas 'PointedEars' Lahn wrote:
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.
Usually. But the spec has examples of sections that don't seem to
follow that convention. For example:

What about slice: 15.4.4.10 Array.prototype.slice(start, end)

or sort: 15.4.4.11 Array.prototype.sort(comparefn)

These don't have brackets around optional arguments. The
arguments are optional in all modern (non-beta) implementations.
Non sequitur.
Shows that optional arguments are treated as undefined.
If anything, it shows that that the specification is worded
imprecisely. Which point are you trying to make here?
Weren't you saying that non-square bracketed arguments were mandatory?

Not so, I did not.
The square brackets don't have a defined meaning.

Yes, they have.

So what is clearly defined meaning?
Again, for the intellectually challenged among us: I am arguing instead that
brackets would give an indication as to which arguments are optional and
which are not;

So the "clearly defined meaning" is the argument of Thomas 'PointedEars'
Lahn.

however, as the Specification is obviously worded
imprecisely, the Specification prose also counts. If there is nothing in
the prose/algorithm of a method to define what is to be done when certain
arguments are omitted, it is not reasonable to call one return value wrong
and one right. Period.


Non sequitur. You misunderstood completely what I was saying;

I'm not sure that anyone understood completely what you were saying.
Sprinkling your argument with put downs doesn't exactly make it clearer.

given your
other luser-like behavior, maybe on purpose:
[quoting unreferred parts including my signature again]

Score adjusted

Uh oh. not that again. Thomas, I am trying to engage in a normal
conversation with you. But you seem to be resisting that. I think that's
a bad choice. I thought you wanted to be FAQ maintainer. What happened?

Garrett
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,744
Messages
2,569,483
Members
44,903
Latest member
orderPeak8CBDGummies

Latest Threads

Top