And object with a blank prototype is a little nicer for using as a hash.
You don't have to worry about iterating over they keys with for..in and
getting the Object.prototype properties.
var o = {}
o.toString // function toString() { [native code] }
'toString' in o // true
o = Object.create(null);
o.toString // undefined
'toString' in o // false
You're right that it's often irrelevant despite this because you can't
always be sure the prototype remains unset. And it's not clear whether the
savings from avoiding Object.keys or Object.hasOwnProperty are worth it.
Just wanted to throw that out there for people's education.
:Marco
On Sunday, June 17, 2012 12:45:30 AM UTC-7, Bruno Jouhier wrote:
>
> @marcel,
>
> Why Object.create(null) rather than {}? You'll get a null prototype
> instead of Object.prototype but that's often irrelevant. On the other hand
> you may pay a price for it. I just re-run the benchmark and Object.create
> is 40 time slower than {} on V8 (chrome). On firefox they are equivalent!
>
> http://jsperf.com/object-create-null-vs-literal
>
>
> On Sunday, June 17, 2012 5:46:05 AM UTC+2, vitoa wrote:
>>
>> Tanks a lot for all help :)
>> This var table = Object.create(null); and Object.keys(table) saved my
>> life
>> All my algorith was repalced by a simple table[line[0]]=line;
>> Love nodejs and all help u give to me
>>
>> I have some question about eficiency? does this way off implemeting
>> algortithm eficient in cpu eat?
>>
>> What do you mean wirh ""size" of an object like this is NOT a constant
>> time operation"
>>
>> This table[line[0]]=line; is used frequently in time there is data on
>> serial port serial.on('data', function ).....
>> I receive like 6 or 7 data each 3 seconds, 40bytes for each data
>> contaning this unique id and values to repalce or add to table
>>
>> On future there will be much more data id's, because this is a ZigBee
>> network ..that could receive up to 65000 diferent id's... but for
>> begining this works perfect
>>
>>
>> Best regards nodejs guys,
>> Vitor
>>
>>
>>
--
Job Board: http://jobs.nodejs.org/
Posting guidelines:
https://github.com/joyent/node/wiki/Mailing-List-Posting-Guidelines
You received this message because you are subscribed to the Google
Groups "nodejs" group.
To post to this group, send email to [email protected]
To unsubscribe from this group, send email to
[email protected]
For more options, visit this group at
http://groups.google.com/group/nodejs?hl=en?hl=en