My project contains an ES6 class whose constructor is defined as follows:
constructor() {
this.campaignName = 'United Way';
this.campaign = {};
this.questions = {};
this.benefits = {};
this.assistors = {};
this.locations = {};
this.buildDataObjects = this.buildDataObjects.bind(this);
this.retrieve();
}
Later in the code, the properties with default values of empty objects are given new values using Object.assign; however, I do not believe that code has any relevance for solving the problem at hand, so it is not included.
Elsewhere in the project's codebase, an instance of the class is being output using console.info:
As evident from the screenshot, there is seemingly nothing unusual about the object.
Next, the object's "questions" property is output:
The first line in the screenshot is an empty object, even though the output below includes the object's properties. However, those properties are inaccessible, as evident by the fact that calling Object.keys
with the given object produces an empty array.
I am at a total loss as to the cause of this behavior and would appreciate some insight. Thanks in advance!
As @Andreas pointed out, the console output was being performed before the assignment of a new value to "questions" was completed.
As a side-note, my confusion was exacerbated by the presence of properties below the empty object in the console output, which are apparently somehow appended after the fact.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.