can-define
can-define copied to clipboard
.set is confusing in how it work on plain DefineMaps versus extended DefineMaps
The Problem
The documentation for .set
located at https://canjs.com/doc/can-define/map/map.prototype.set.html states:
Assigns value to a property on this map instance called propName. This will define the property if it hasn't already been predefined.
This (defining a property, not previously defined) works for plain (not extended) DefineMaps, but fails to work on the example below.
const MyMap = DefineMap.extend({});
const mapB = new MyMap({});
mapB.set("propA", "value");
The Solution
The documentation for .set
should state (very plainly) that you cannot extend an extended DefineMap and the error it would throw if you try.
As a bonus it might be worth explain /why/ an extended DefineMap is sealed where as a plain DefineMap is not.