[ Поиск ] - [ Пользователи ] - [ Календарь ]
Полная Версия: get/set как его использовать
denis_alekss
Решил понять смысл get/set, написал небольшой код, правильно ли в нем используется
метод get/set или нужно по-другому, если по-другому, напишите пож. как лучше в моем коде.

<script>
class
Beverage{
constructor(options){
this.name = options.name;
}
returnName() {console.log(this.name)}
}


class Price extends Beverage
{
constructor(options){
super(options)
this.price = options.price;
this.bos = options.bos;
}

result() {console.log("Напиток " + this.name + " Цена" + this.price + "Директор - " + this.bos)}

get Bos(){
{
return result()}
}


set Bos(newBos){
const newbos = newBos.split(' ');
this.bos = newbos[0];
this.bos = newbos[1]
}
}


const bev = new Beverage({name: 'Coca-cola'})
bev.returnName()

const price = new Price({name: 'Fanta',price: " - 200 евро ",bos: "Стивен"})
price.result()

price.bos = "Майкл Джексон"
price.result()
</script>
Быстрый ответ:

 Графические смайлики |  Показывать подпись
Здесь расположена полная версия этой страницы.
Invision Power Board © 2001-2024 Invision Power Services, Inc.