function FakeStorage() {
  this.clear();
}

FakeStorage.prototype = {
  key(index) {
    // sanitise index as int
    index = parseInt(index);
    // return early if index isn't a positive number or larger than length
    if (isNaN(index) || index < 0 || index >= this.length) {
      return null;
    }
    // loop through data object until at nth key
    let i = 0;
    for (const key in this._data) {
      if (this._data.hasOwnProperty(key)) {
        if (i === index) {
          return key;
        }
        i++;
      }
    }
    // otherwise return null
    return null;
  },

  getItem(key) {
    // only get if there's something to get
    return this._data.hasOwnProperty(key) ? this._data[key] : null;
  },

  setItem(key, value) {
    // if we're adding a new item, increment the length
    if (!this._data.hasOwnProperty(key)) {
      this.length++;
    }
    // always store the value as a string
    this._data[key] = value.toString();
  },

  removeItem(key) {
    // only remove if there's something to remove
    if (this._data.hasOwnProperty(key)) {
      delete this._data[key];
      this.length--;
    }
  },

  clear() {
    this._data = {};
    this.length = 0;
  },
};

export default FakeStorage;

@@ -1,285 +1,56 @@
-function FakeStorage() %7B%0A  this.clear();%0A%7D%0A%0AFakeStorage.prototype = %7B%0A  key(index) %7B%0A    // sanitise index as int%0A    index = parseInt(index);%0A    // return early if index isn't a positive number or larger than length%0A    if (isNaN(index) %7C%7C index %3C 0 %7C%7C index %3E= this.length
+class FakeStorage %7B%0A  #data = %7B%7D;%0A%0A  get length(
 ) %7B%0A
-  
     
@@ -60,289 +60,117 @@
 urn 
-null;%0A    %7D%0A    // loop through data object until at nth key%0A    let i = 0;%0A    for (const key in 
+Object.keys(
 this.
-_
+#
 data)
- %7B%0A      if (this._data.hasOwnProperty(key)) %7B%0A        if (i === index) %7B%0A          return key;%0A        %7D%0A        i++;%0A      %7D%0A    %7D%0A    // otherwise return null%0A    return
+.length;%0A  %7D%0A%0A  key(n) %7B%0A    return Object.keys(this.#data)%5BNumber.parseInt(n, 10)%5D ??
  nul
@@ -171,25 +171,24 @@
 ?? null;%0A  %7D
-,
 %0A%0A  getItem(
@@ -202,107 +202,147 @@
     
-// only get if there's something to get%0A    return this._data.hasOwnProperty(key) ? this.
+const _data = this.#data;%0A    const _key = %60$%7Bkey%7D%60;%0A    return Object.prototype.hasOwnProperty.call(_data, _key)%0A      ? 
 _data%5B
+_
 key%5D
+%0A     
  : n
@@ -345,25 +345,24 @@
  : null;%0A  %7D
-,
 %0A%0A  setItem(
@@ -383,216 +383,55 @@
     
-// if we're adding a new item, increment the length%0A    if
+return
  (
-!
 this.
-_
+#
 data
-.hasOwnProperty(key)) %7B%0A      this.length++;%0A    %7D%0A    // always store the value as a string%0A    this._data%5Bkey
+%5B%60$%7Bkey%7D%60
 %5D = 
+%60$%7B
 value
-.toString(
+%7D%60
 );%0A  %7D
-,
 %0A%0A  
@@ -444,24 +444,31 @@
 Item(key
+, value
 ) %7B%0A    
 // only 
@@ -463,72 +463,85 @@
     
-// only remove if there's something to remove%0A    if (this._data
+const _data = this.#data;%0A    const _key = %60$%7Bkey%7D%60;%0A    if (Object.prototype
 .has
@@ -551,17 +551,30 @@
 Property
-(
+.call(_data, _
 key)) %7B%0A
@@ -590,46 +590,21 @@
 ete 
-this.
 _data%5B
+_
 key%5D;%0A
-      this.length--;%0A
     
@@ -608,17 +608,16 @@
    %7D%0A  %7D
-,
 %0A%0A  clea
@@ -618,16 +618,26 @@
   clear(
+key, value
 ) %7B%0A    
@@ -641,17 +641,17 @@
    this.
-_
+#
 data = %7B
@@ -657,36 +657,13 @@
 %7B%7D;%0A
-    this.length = 0;%0A
   %7D
-,
 %0A%7D
-;
 %0A%0Aex

Rewrite using modern JavaScript features