Trying to get the following code to work; As the store variable is assigned an anonymous object, the “data” property is populated using a function call. This setting should also set the contents of the other object’s property “masterData”. I expected the “this” keyword to refer to the anonymous object being created, but I’m wrong…
var store = {
masterData : [],
revert: function() {
this.data = shallowCopy(this.masterData);
},
data: (function() {
var overviewData = getOverviewData();
this.masterData = overviewData;
return chartData;
}).call(),
};
See also that “revert” property; It’s given a function that’ll create a copy of the object’s data property contents.
What should be used, since “this” returns the DOMWindow object?
The
datafunction is being called before the object is defined;thiswill not be an alias to an object prior to that object’s coming into existence. You can use a constructor function with a private, short-lived variable: