can-define icon indicating copy to clipboard operation
can-define copied to clipboard

.set is confusing in how it work on plain DefineMaps versus extended DefineMaps

Open mjstahl opened this issue 6 years ago • 0 comments

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.

mjstahl avatar Oct 12 '18 11:10 mjstahl