On Fri, May 24, 2013 at 3:53 AM, 刘玉龙 <[email protected]> wrote:
> Hey, I have another question.
>
> I noticed that jquery, underscore and some other libraries, don't check if
> the index is in array. Under what circumstances this lacking of check will
> cause a bug?
>
That depends on your definition of "bug"; or, put differently: on your
program's expectations how missing elements should be treated when walking
over an array. Consider this example:
> var a = [1,,,4]
> a.forEach(function(x) { console.log(x);})
1
4
> for (var i = 0; i < a.length; ++i) console.log(a[i])
1
undefined
undefined
4
> Thank you.
>
> 在 2013年5月23日星期四UTC+8下午4时51分21秒,Jakob Kummerow写道:
>>
>> Here's what the builtin forEach function does: https://code.google.com/**
>> p/v8/source/browse/branches/**bleeding_edge/src/array.js#**1078<https://code.google.com/p/v8/source/browse/branches/bleeding_edge/src/array.js#1078>
>>
>> Notably, for every index it checks if the array actually contains that
>> index. This check is mandated by the ECMAScript specification, see
>> http://www.ecma-**international.org/**publications/files/ECMA-ST/**
>> Ecma-262.pdf<http://www.ecma-international.org/publications/files/ECMA-ST/Ecma-262.pdf>
>> chapter 15.4.4.**18.
>>
>> On Thu, May 23, 2013 at 10:37 AM, 刘玉龙 <[email protected]> wrote:
>>
>>> I found an interesting thing in V8 engine when I was testing
>>> underscore.js library.
>>>
>>> For arrays, the
>>>
>>>> for (var i = 0; i < len; i++)
>>>
>>> implementation can ran 24700 ops(operations per second), while the
>>> native function
>>>
>>>> Array.prototype.forEach
>>>
>>> only got 14200 ops.
>>>
>>> Then I tried IE10, in which the `nativeForEach` can reach a number of
>>> 43500.
>>>
>>> I checked the source code of V8 engine, but could not find out why this
>>> native forEach function is so slow.
>>> Can anybody explain this? Thank you.
>>>
>>> --
>>> --
>>> v8-users mailing list
>>> [email protected]
>>>
>>> http://groups.google.com/**group/v8-users<http://groups.google.com/group/v8-users>
>>> ---
>>> You received this message because you are subscribed to the Google
>>> Groups "v8-users" group.
>>> To unsubscribe from this group and stop receiving emails from it, send
>>> an email to v8-users+u...@**googlegroups.com.
>>>
>>> For more options, visit
>>> https://groups.google.com/**groups/opt_out<https://groups.google.com/groups/opt_out>
>>> .
>>>
>>>
>>>
>>
>> --
> --
> v8-users mailing list
> [email protected]
> http://groups.google.com/group/v8-users
> ---
> You received this message because you are subscribed to the Google Groups
> "v8-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to [email protected].
> For more options, visit https://groups.google.com/groups/opt_out.
>
>
>
--
--
v8-users mailing list
[email protected]
http://groups.google.com/group/v8-users
---
You received this message because you are subscribed to the Google Groups
"v8-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email
to [email protected].
For more options, visit https://groups.google.com/groups/opt_out.