JSFiddle - React, Tailwind, and code Playground
by Mariya_Korotkova
JavaScript
/* function Machine(power) {
this._enabled = false;
this.enable = function() {
this._enabled = true;
};
this.disable = function() {
this._enabled = false;
};
}
function CoffeeMachine(power) {
Machine.apply(this, arguments);
const waterAmount = 0;
this.setWaterAmount = function(amount) {
this.waterAmount = amount;
};
const parentEnable = this.enable;
this.enable = function() {
parentEnable();
this.run();
}
function onReady() {
console.log('Кофе готово!');
}
this.run = function() {
setTimeout(onReady, 1000);
};
}
const coffeeMachine = new CoffeeMachine(10000);
console.log(coffeeMachine)
coffeeMachine.setWaterAmount(50);
coffeeMachine.enable();
class Person {
constructor(firstName, lastName) {
this.firstName = firstName;
this.lastName = lastName;
}
getFullName() {
return `${this.firstName} ${this.lastName}`;
}
}
const person = new Person('Dan', 'Abramov')
person.getFullName() //> "Dan Abramov"
person.lastName //> "Abramov"
class User extends Person {
constructor(firstName, lastName, email, password) {
super(firstName, lastName);
this.email = email;
this.password = password;
}
getEmail() {
return this.email;
}
getPassword() {
return this.password;
}
}
function App() {
const user = new User('Dan', 'Abramov', '[email protected]', 'iLuvES6');
user.getFullName(); //> "Dan Abramov"
user.getEmail(); //> "[email protected]"
user.getPassword(); //> "iLuvES6"
user.firstName; //> "Dan"
user.lastName; //> "Abramov"
user.email; //> "[email protected]"
user.password //> "iLuvES6"
}
*/
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;
} else {
...