diff --git a/module/data/fields/iterableTypedObjectField.mjs b/module/data/fields/iterableTypedObjectField.mjs index 6d00763f..d50d7dbf 100644 --- a/module/data/fields/iterableTypedObjectField.mjs +++ b/module/data/fields/iterableTypedObjectField.mjs @@ -6,25 +6,27 @@ export default class IterableTypedObjectField extends foundry.data.fields.TypedO #elementClass; - initialize(value) { - return new IterableObject(value, this.#elementClass); + /** Initializes an object with an iterator. This modifies the prototype instead of */ + initialize(values) { + const object = Object.create(IterableObjectPrototype); + for (const [key, value] of Object.entries(values)) { + object[key] = new this.#elementClass(value); + } + return object; } } -class IterableObject { - constructor(values, elementClass) { - for (const [key, value] of Object.entries(values)) { - this[key] = new elementClass(value); - } - } - - *[Symbol.iterator]() { +/** + * The prototype of an iterable object. + * This allows the functionality of a class but also allows foundry.utils.getType() to return "Object" instead of "Unknown". + */ +const IterableObjectPrototype = { + [Symbol.iterator]: function*() { for (const value of Object.values(this)) { yield value; } - } - - map(func) { + }, + map: function (func) { return Array.from(this, func); } -} +}; \ No newline at end of file