无法启动时调用Array.splice({}) [英] Calling Array.splice({}) with no start

查看:83
本文介绍了无法启动时调用Array.splice({})的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Array.splice({})


它应该做什么?


我认为它应该返回一个长度为0的新数组。


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


示例:

Array.splice({})


结果:

FF3.1

函数splice(){[native code]}

Webkit:

undefined

如果 - start - 被传入,则返回一个0长度的数组。

Array.prototype.splice.call(0,undefined);

结果:[]


计算 - length - 属性的方法全部调用

ToNumber,通过ToUint32或ToInteger。 ToNumber coverts

undefined为NaN,它将值返回给它的调用者,或者是
ToInteger或ToUint32,它将NaN转换为+0。

似乎第4步不是我的期望:

| 4.调用ToInteger(开始)。

从参数列表中省略
start,我认为这意味着start =

undefined。


ToInteger调用ToNumber。

ToInteger:

| 1.在输入参数上调用ToNumber。

| 2.如果结果(1)是NaN,则返回+0。

....


ToNumber返回NaN:

| 9.3 ToNumber

|运算符ToNumber转换其参数

|根据下表中的数字类型值:

| ----------- + ----- +

|未定义| NaN |

`....------- + ----- +


返回ToInteger,第2步。

| 2.如果Result(1)是NaN,则返回+0。

解决方案

dhtml写道:


那将是:

javascript :alert(Array.prototype.isPrototypeOf(

Array.prototype.splice.call({ }))


结果:

Opera9.5 mac:

true

FF3。 1,Webkit

false


Garrett


8月19日,07:59,dhtml < dhtmlkitc ... @ gmail.comwrote:


Array.splice({})


它应该怎么做?


我认为它应该返回一个长度为0的新数组。


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



我只是偶尔的海报而不是专家,但我是摔倒这里有一个
巨魔?


Array.splice({})在语义上完全没有意义。


a)Splice是数组对象的方法,而不是Array global的方法

object。

b)" {}"是一个空对象而不是长度为0的数组。


所以我猜你的意思是[] .splice()


但是

c)start和deleteCount参数是强制性的,所以谁关心

不同的引擎在这种不确定的情况下返回什么?


Robin


8月19日下午2:40,Robin Rattay写道:


On 19 8月,07:59,dhtml写道:


> Array.splice({})


>它应该怎么办?


>我认为它应该返回一个长度为0的新数组。


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



我只是一张偶尔的海报,而不是专家,但是我在这里为一个巨魔而堕落了吗?



如果OP实际上已经做了一些

(任意)点,那将更容易判断。


Array.splice({})在语义上完全没有意义。


a)Splice是数组对象的方法,而不是

数组全局对象。



这可能只是误导了数组的使用。表示任何数组对象。

当然有很多不那么模糊的表达方式,如果它是意图的话。


b)" {}"是一个空对象而不是长度为0的数组。


所以我猜你的意思是[] .splice()



更有可能 - [] .slice({}) - 否则

中没有任何意义提到ToInteger中的对象处理(没有
$ b对Object.prototype.toString / valueOf的$ b修改将返回数字

零)。


但是

c )start和deleteCount参数是必需的,



否则它们不是(至少在从

方法调用中省略它们的意义上)不会导致错误并且会有一个可预测的/
指定的结果。


所以谁关心不同引擎返回的内容

一个未定义的案例?



如果结果与给定实施的任何

中的指定结果不符,那么这些实施者可能会关心。


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.

解决方案

dhtml wrote:

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

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

Garrett


On 19 Aug., 07:59, dhtml <dhtmlkitc...@gmail.comwrote:

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


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?

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.


这篇关于无法启动时调用Array.splice({})的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆