-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathscript.js
More file actions
127 lines (98 loc) · 3.57 KB
/
script.js
File metadata and controls
127 lines (98 loc) · 3.57 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
// Импорт модуля
// import {
// addProductToCart,
// totalPrice as price,
// quantity,
// } from './shopping-cart.js';
// // console.log(shippingCost);
// addProductToCart('рубашка', 2);
// console.log(price, quantity);
// import * as ShoppingCart from './shopping-cart.js';
// console.log('Импорт модуля');
// ShoppingCart.addProductToCart('рубашка', 2);
// console.log(ShoppingCart.totalPrice);
// import addToCart, {
// addProductToCart,
// totalPrice as price,
// quantity,
// } from './shopping-cart.js';
import addToCart, { cart } from './shopping-cart.js';
addToCart('рубашка', 2);
addToCart('носки', 2);
addToCart('трусы', 2);
// console.log(cart);
// // const result = await fetch('https://jsonplaceholder.typicode.com/posts');
// // const data = await result.json();
// // console.log(data);
// // console.log('Код после await');
// const getLastPost = async function () {
// const result = await fetch('https://jsonplaceholder.typicode.com/posts');
// const data = await result.json();
// console.log(data);
// return { title: data.at(-1).title, postText: data.at(-1).body };
// };
// const lastPostData = getLastPost();
// console.log(lastPostData);
// lastPostData.then(data => console.log(data));
// const lastPostData1 = await getLastPost();
// console.log(lastPostData1);
///////////////////////////////////////////////
// Шаблон Проектирования Модуль
// const ShoppingCart1 = (function () {
// const cart = [];
// const shippingCost = 20;
// const totalPrice = 300;
// const totalQuantity = 10;
// const addProductToCart = function (product, quantity) {
// cart.push({ product, quantity });
// console.log(
// `${product} в количестве ${quantity} шт добавлено в корзину, цена доставки ${shippingCost}`
// );
// };
// const productOrderedMessage = function (product, quantity) {
// console.log(`${product} в количестве ${quantity} шт заказан`);
// };
// return {
// addProductToCart,
// cart,
// totalPrice,
// totalQuantity,
// };
// })();
// ShoppingCart1.addProductToCart('апельсин', 5);
// ShoppingCart1.addProductToCart('кола', 1);
// console.log(ShoppingCart1);
///////////////////////////////////////////////
// Модули CommonJS
// Экспорт чего-либо
// export.addProductToCart = function (product, quantity) {
// cart.push({ product, quantity });
// console.log(
// `${product} в количестве ${quantity} шт добавлено в корзину, цена доставки ${shippingCost}`
// );
// };
// // Импорт
// const { addProductToCart } = require('./shopping-cart.js');
////////////////////////////////////////////////
// Использование библиотеки lodash-es
// import cloneDeep from './node_modules/lodash-es/cloneDeep.js';
// import cloneDeep from 'lodash';
// const state = {
// cart: [
// { product: 'яблоко', quantity: 5 },
// { product: 'апельсин', quantity: 3 },
// ],
// user: { loggedIn: true },
// };
// const stateCopy = Object.assign({}, state);
// const stateDeepCopy = cloneDeep(state);
// state.user.loggedIn = false;
// console.log(stateCopy);
// console.log(stateDeepCopy);
// if (module.hot) {
// module.hot.accept();
// }
// Promise.resolve('Testing').then(a => console.log(a));
// import 'core-js/stable';
// // Полифиллинг асинхронных функций
// import 'regenerator-runtime/runtime';