montagejs / collections

This package contains JavaScript implementations of common data structures with idiomatic interfaces.
http://www.collectionsjs.com
Other
2.09k stars 185 forks source link

collections.getDefault() (and .get() with a default arg) seems completely broken on Map #176

Open cdmcmahon opened 7 years ago

cdmcmahon commented 7 years ago

Copy and paste the following into RunKit and I would expect the second and third console.log statements to print 'def', but they print undefined. Perhaps I'm missing something? The documentation seems pretty clear so I'm somewhat at a loss.

const Map = require('collections/map');

const foo = new Map();

foo.set('a', 'aa');
foo.set('b', 'bb');
foo.set('c', 'cc');

// EXISTING VALUE

let a = foo.get('a');
console.log(a);
// >>> 'aa'

// DEFAULT ARGUMENT

let def = foo.get('d', 'def');
console.log(def);
// >>> undefined

// DEFAULT FUNCTION SET

foo.getDefault = function() { 
    return 'def';
};

let def2 = foo.get('d');
console.log(def2);
// >>> undefined