Could anyone explain the difference between this:
Update 1- reverting phrases
container.data("state", { test: 1 }); // works
and this:
container.data["state"] = { test: 1 }; // doesn't work
I found that the first construction works, while the last one doesn’t. The call populates container with the initial data, i.e. “state” is blank when it’s called.
datais a function, not an array. You’re trying to access an index of a function in the second snippet, which doesn’t work.See the docs: http://api.jquery.com/jQuery.data/
For example, open up your Development Console in your browser, and type something like this:
I get a long function definition, not an array: