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

ShimArray get method bug, may be more in the source. #195

Open troring opened 6 years ago

troring commented 6 years ago
    var players = new ShimArray(3);
    var v1 = players.get(1);
    var v2 = players.get(1,0);
    players.set(1,25);
    var v3 = players.get(5,0);
    // result: v1 = v2 = v3 = undefined

source code:

define("get", function (index, defaultValue) {
    if (+index !== index) {
        throw new Error("Indicies must be numbers");
    } else if (!index in this) {  <---should be !(index in this)
        return defaultValue;
    } else {
        return this[index];
    }
});