>> // ES6
>> function* entries(obj){
>> for (let key in obj) {
>> yield [key, obj[key]];
>> }
>> }
>
>
> cool, but why do we need that exactly ?
The one suggestion I can make is that generators mean you don't have
to calculate the entire answer up front.
This is well demonstrated by Brandon's code examples. This could be a
nice performance gain under certain circumstances.
>>
>>
>> // ES3-5 version
>> function entries(obj){
>> var keys = [];
>> var index = 0;
>> for (keys[index++] in obj);
>> var total = index;
>> index = 0;
>> return {
>> next: function(){
>> if (index < total) {
>> var key = keys[index++];
>> return { done: false, value: [key, obj[key]] }
>> }
>> return { done: true };
>> }
>> };
>> }
>
>
> have you guys read this article ? where it talks about JS people not
> thinking about GC and RAM ?
> http://sealedabstract.com/rants/why-mobile-web-apps-are-slow/
>
I have read the article, I found it interesting. I was just wondering
if the 'const' keyword would help give JS another small performance
boost.
As Andreas points out the major issue is that JS is highly dynamic,
this can be very useful sometimes but for most code it's not required.
Maybe if you mark everything as const or freeze/seal classes then
maybe JS engines will optimize for that code.
One issue that could help with is memory allocation for JS objects,
maybe that will make it easier to know how much memory to allocate
for a class, or JS object if it's marked as a const. I don't know for
sure as I lack the knowledge, I do know that in ES6 code I will use
const as
my new var.
_______________________________________________
es-discuss mailing list
[email protected]
https://mail.mozilla.org/listinfo/es-discuss