code: function(sort) {
    this._array = [];
    this._sort = sort;
  
    Object.defineProperty(this, 'length', {
      enumerable: true,
      get: function() { return this._array.length },
    });
  
    if (typeof this._sort !== 'function') {
      this._sort = function(a, b) {
        return a - b;
      }
    }
  }
docs: heap.js
  JS heap implementation