Skip to content

Instantly share code, notes, and snippets.

@liushuping
Last active August 29, 2015 14:23

Revisions

  1. liushuping revised this gist Jun 15, 2015. 1 changed file with 2 additions and 1 deletion.
    3 changes: 2 additions & 1 deletion gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -6,7 +6,8 @@ default a key in the map.
    var x = {};
    x["toString"]; // function toString()
    But with the Object.create method, we can create a real empty map object. What needed is just to pass null to the method.
    But with the Object.create method, we can create a real empty map object. What needed is just to pass null to
    the method.
    */

    var map = Object.create(null);
  2. liushuping revised this gist Jun 15, 2015. 1 changed file with 5 additions and 6 deletions.
    11 changes: 5 additions & 6 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -1,14 +1,13 @@
    /*
    A JavaScript object notition is by nature a map, however there are limitations of it: the map is not empty,
    the Object prototype properties are mapped keys which are unexpected. For below example, the "toString" is by
    default a key in the map.
    */
    A JavaScript object notition is by nature a map, however there are limitations of it: the map is not empty,
    the Object prototype properties are mapped keys which are unexpected. For below example, the "toString" is by
    default a key in the map.
    var x = {};
    x["toString"]; // function toString()
    /*
    With the Object.create method, we can create a real empty map object. What needed is just to pass null to the method.
    But with the Object.create method, we can create a real empty map object. What needed is just to pass null to the method.
    */

    var map = Object.create(null);
    console.log(map["toString"]); // undefined
  3. liushuping created this gist Jun 15, 2015.
    14 changes: 14 additions & 0 deletions gistfile1.js
    Original file line number Diff line number Diff line change
    @@ -0,0 +1,14 @@
    /*
    A JavaScript object notition is by nature a map, however there are limitations of it: the map is not empty,
    the Object prototype properties are mapped keys which are unexpected. For below example, the "toString" is by
    default a key in the map.
    */

    var x = {};
    x["toString"]; // function toString()

    /*
    With the Object.create method, we can create a real empty map object. What needed is just to pass null to the method.
    */
    var map = Object.create(null);
    console.log(map["toString"]); // undefined