JSFiddle - React, Tailwind, and code Playground

by Mariya_Korotkova

JavaScript

function Grid(rows) {
	this.rows = rows;
  console.log(rows);
  this.rowsCount = rows.length;
  this.colsCount = this._calculateCols();
}

Grid.prototype.getRowsCount = function() {
	 return this.rowsCount;
}

Grid.prototype.getColsCount = function() {
	 return this.colsCount;
}

Grid.prototype._calculateCols = function() {
	 if (this.rows.length) {
      return Object.keys(this.rows[0]).length;
    } else {
      return 0;
    }
}

Grid.prototype.getTableName = function() {
	 return 'Grid';
}

Grid.prototype.getConfig = function() {
	return {
      rowsCount: this.rowsCount,
      colsCount: this.colsCount,
    }
}

function User(rows, login, email) {
	Grid.call(this, rows);
	this.login = login;
  this.email = email;
}

User.prototype = Object.create(Grid.prototype);
User.prototype.constructor = User;

User.prototype.getUserName = function() {
	return this.userName;
}

User.prototype.getEmail = function() {
	return this.email;
}

User.prototype.getConfig = function() {
	
  const GRID_CONFIG = Grid.prototype.getConfig.apply(this);
    return {
      ...GRID_CONFIG,
      login: this.login,
      email: this.email,
    }
}

User.prototype.getTableName = function() {
	return 'User';
}

/* 
class User extends Grid {
  constructor(rows, login, email) {
    super(rows);
    this.login = login;
    this.email = email;
  }

  getUserName() {
    return this.userName;
  }

  getEmail() {
    return this.email;
  }
  
  getTableName() {
    return 'User';
  }

  getUserConfig() {
    const GRID_CONFIG = super.getConfig();
    return {
      ...GRID_CONFIG,
      userName: this.userName,
      email: this.email,
    }
  }

  
} */

/* class Grid {
  constructor(rows) {
    this.rows = rows;
    this.rowsCount = rows.length;
    this.colsCount = this._calculateCols();
  }

  getRowsCount() {
    return this.rowsCount;
  }

  getColsCount() {
    return this.colsCount;
  }

  _calculateCols() {
    if (this.rows.length) {
      return Object.keys(this.rows[0]).length;
    }...