-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy path5.object-literals.js
72 lines (57 loc) · 1.26 KB
/
5.object-literals.js
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
//example a
function createBookShop(inventory) {
return {
inventory,
inventoryValue() {
return this.inventory.reduce((total, book) => total + book.price, 0);
},
priceForTitle(title) {
return this.inventory.find(book => book.title === title).price;
}
};
}
const inventory = [
{ title: 'Harry Potter', price: 10 },
{ title: 'Eloquent Javascript', price: 15 }
];
const bookShop = createBookShop(inventory);
console.log(bookShop.inventoryValue());
console.log(bookShop.priceForTitle('Harry Potter'));
//example b
function saveFile(url, data) {
$.ajax({
url,
data,
method: 'POST'
}); //jquery request plx
}
const url = 'http://fileupload.com';
const data = { color: 'red' };
saveFile(url, data);
//examples
//a
const red = '#ff0000';
const blue = '#0000ff';
const COLORS = { red, blue };
//b
const fields = ['firstName', 'lastName', 'phoneNumber'];
const props = { fields };
//c
const canvasDimensions = function (width, initialHeight) {
const height = initialHeight * 9 / 16;
return {
width,
height
};
}
//d
const color = 'red';
const Car = {
color,
drive() {
return 'Vroom!';
},
getColor() {
return this.color;
}
};