diff --git a/src/types/observablemap.ts b/src/types/observablemap.ts index 24f1e261a..12408040b 100644 --- a/src/types/observablemap.ts +++ b/src/types/observablemap.ts @@ -73,8 +73,8 @@ export type IObservableMapInitialValues = IMapEntries | IKeyValueMap | export class ObservableMap implements IInterceptable>, IListenable, IMap { $mobx = ObservableMapMarker; - private _data: { [key: string]: ObservableValue } = {}; - private _hasMap: { [key: string]: ObservableValue } = {}; // hasMap, not hashMap >-). + private _data: { [key: string]: ObservableValue } = Object.create(null); + private _hasMap: { [key: string]: ObservableValue } = Object.create(null); // hasMap, not hashMap >-). private _keys: IObservableArray = new ObservableArray(undefined, referenceEnhancer, `${this.name}.keys()`, true); interceptors = null; changeListeners = null; diff --git a/test/map.js b/test/map.js index aa86c1a41..205bd8abf 100644 --- a/test/map.js +++ b/test/map.js @@ -603,3 +603,20 @@ test('using deep map', t => { t.end(); }); + +test("issue 893", t => { + const m = mobx.observable.map(); + const keys = ['constructor', 'toString', 'assertValidKey', 'isValidKey', 'toJSON', 'toJS'] + for (let key of keys) { + t.equal(m.get(key), undefined); + } + t.end(); +}); + +test("work with 'toString' key", t => { + const m = mobx.observable.map(); + t.equal(m.get('toString'), undefined); + m.set('toString', 'test'); + t.equal(m.get('toString'), 'test'); + t.end(); +}); \ No newline at end of file