class Pizza {
constructor() {
this.crust = prompt('Choose your crust: ');
this.toppingsCount = +prompt('How many toppings do you want?') || 0;
this.toppings = [];
}
makeToppings() {
const {toppings, toppingsCount} = this;
for(let i = toppingsCount; i--;) {
toppings.push(prompt('Choose your topping: '));
}
}
makePizza() {
const {crust, toppings} = this;
return `Your order is done! You choose ${crust} crust with these toppings: ${toppings.length ? toppings.join(', ') : 'nothing'}`;
}
}
let personalPizza = new Pizza();
personalPizza.makeTopping();
console.log(personalPizza.makePizza());
import chain from '@bingo347/fn/mappers/chain';
import extractField from '@bingo347/fn/mappers/extractField';
// создаем функцию для безопасного извлечения
const getBCDE = chain(
extractField('B'),
extractField('C'),
extractField('D'),
extractField('E')
);
// извлекаем
const ABCDE = getBCDE(A);
const TestClass = (function() {
class TestClass {
constructor() {
this.calls = '';
}
toString() {
return this.calls;
}
}
Object.setPrototypeOf(TestClass.prototype, Function.prototype);
function callTestClassInstance(el) {
this.calls += String(el);
}
return new Proxy(TestClass, {
construct(TestClass, args) {
const instance = new TestClass(...args);
const target = args => callTestClassInstance.apply(instance, args);
Object.setPrototypeOf(target, TestClass.prototype);
return new Proxy(target, {
apply(target, _, args) {
return target(args);
},
get(_, name) {
return instance[name];
},
set(_, name, value) {
instance[name] = value;
return true;
},
has(_, name) {
return name in instance;
},
deleteProperty(_, name) {
return delete instance[name];
},
defineProperty(_, name, descriptor) {
return Object.defineProperty(instance, name, descriptor);
},
getOwnPropertyDescriptor(_, name) {
return Object.getOwnPropertyDescriptor(instance, name);
},
ownKeys() {
return Object.getOwnPropertyNames(instance).concat(Object.getOwnPropertySymbols(instance));
}
});
}
});
})();
const appleDevice = /iP(hone|od|ad)/;
const applePhone = /iPhone/i;
const appleIPod = /iPod/i;
const appleTablet = /iPad/i;
const androidPhone = /(?=.*\bAndroid\b)(?=.*\bMobile\b)/i;
const androidTablet = /Android/i;
const windowsPhone = /Windows Phone/i;
const windowsTablet = /(?=.*\bWindows\b)(?=.*\bARM\b)/i;
const otherBlackberry = /BlackBerry/i;
const otherOpera = /Opera Mini/i;
const otherFirefox = /(?=.*\bFirefox\b)(?=.*\bMobile\b)/i;
const sevenInch = /(?:Nexus 7|BNTV250|Kindle Fire|Silk|GT-P1000)/i;
function match(regex, target = navigator.userAgent) {
return regex.test(target);
}
export const isAppleDevice = match(applePhone) || match(appleIPod) || match(appleTablet) || match(appleDevice, navigator.platform);
export const isAndroidDevice = match(androidPhone) || match(androidTablet);
export const isWindowsDevice = match(windowsPhone) || match(windowsTablet);
export const isOtherDevice = match(otherBlackberry) || match(otherOpera) || match(otherFirefox);
export const isSevenInch = match(sevenInch);
export const isMobileDevice = isAppleDevice || isAndroidDevice || isWindowsDevice || isOtherDevice || isSevenInch;
export const isEmulator = isMobileDevice && !isWindowsDevice && (match(/Mac/, navigator.platform) || match(/Win32/, navigator.platform));