Reputation: 24815
Currently I have a simple knockoutJS object, with a few observables. But this object is to grow in the future (that's a fact).
The object is filled with user information about the logged in user (with facebook JavaScript SDK).
The question now is, when I loose the user (logs out) I want to clear my user object. Currently I just would do every element manually (type them out). But this is not functionality I would like to have.
Is there a way (a function of some sort) that loops through all elements and just empties them all? Or is best practice to do it manually.
With manually I mean:
myObject.var("");
myObject.var2("");
myObject.array([]);
etc...
Upvotes: 0
Views: 77
Reputation: 60767
Since this is a custom object, there is no way javascript could guess how you want it to work.
Are all your properties at the top level of your object? Any nested one? Possibilities are endless, therefore there is no built-in function for this.
I'd suggest you create a helper function to empty it. So you don't have to manually do it everytime.
Upvotes: 1