create new object? or reuse existing one?
What is good practice in JavaScript when you need to wipe out data and put
new data?
I use Dojo's Memory and dGrid to display my data. the data gets retrieved
every time user clicks 'refresh' button.
the refresh button won't be called many times during the lifetime of the
application. I have the following code for the grid
store = new Memory();
grid = new OnDemandGrid({
selectionMode: 'single',
store: store
});
and the code above is currently run in the method that initialises the
application.
and I have another method called 'showGrid' which will decide the layout
of the grid.
and the store is updated when the application receives message with new data.
My concern is, Memory does not have method for wiping out its data. so I
have to loop through the store and put the new data. Whereas if I don't
reuse the store and just create new one, it would be easier or faster.
Then why wouldn't I just create store in the 'showGrid' method and let it
creates store every time user clicks refresh? Speed or memory is not a big
concern in the application since data is not that big.
But I want to achieve this in terms of "the correct way" because I learnt
creating new objects when it is reusable is important back in my uni days
(although it was Java Class not JavaScript).
Thanks in advance :)
No comments:
Post a Comment