, 3 JS:
3 ( )
class Rabbit {
constructor() {
this.speed = 3;
}
getSpeed() {
return this.speed;
}
}
let rabbit1 = new Rabbit();
function ConstructorRabbit(){ }
ConstructorRabbit.prototype.speed = 3;
ConstructorRabbit.prototype.getSpeed = function() {
return this.speed;
};
let rabbit2 = new ConstructorRabbit();
const rabbitProto = {
speed: 3,
getSpeed() {
return this.speed;
}
};
function factoryRabbit () {
return Object.create(rabbitProto);
}
let rabbit3 = factoryRabbit();
, , , , , . , " ", , . , , JS ES6, , , .
( ) : ", , , ". , , .