-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathhw4.js
84 lines (76 loc) · 1.92 KB
/
hw4.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
73
74
75
76
77
78
79
80
81
82
83
84
// Задание 1
var pizza = {
name: 'margaritta',
ingredients: ['cheese', 'basil', 'tomato'],
size: [
{ name: 'small', price: 15 },
{ name: 'medium', price: 20 },
{ name: 'large', price: 25}
],
getPrice: function(name){
switch (name) {
case 'small':
return this.size[0].price;
break;
case 'medium':
return this.size[1].price;
break;
case 'large':
return this.size[2].price;
break;
default:
console.log('error')
break;
}
}
}
console.log(pizza.getPrice('medium'));
// Задание 2
function Pizza(name, ingredients, size){
this.name = name;
this.ingredients = ingredients;
this.size = size;
this.getPrice = function (name) {
switch (name) {
case 'small':
return this.size[0].price;
break;
case 'medium':
return this.size[1].price;
break;
case 'large':
return this.size[2].price;
break;
default:
console.log('error')
break;
}
}
}
var margaritta = new Pizza('margaritta', ['cheese', 'basil', 'tomato'], [
{ name: 'small', price: 15 },
{ name: 'medium', price: 20 },
{ name: 'large', price: 25 }
])
console.log(margaritta);
// задание 3
var object = {
name: 'Petya',
method: function () {
return this.name;
}
}
// console.log(object.method());
function myFunc(text) {
return this.name + text;
}
var qwe = myFunc.bind(object);
// console.log(qwe());
function myBind(oldFunc, obj, arg) {
return function () {
return oldFunc.call(obj, arg);
}
}
// console.log(myBind(myFunc, object));
var ewq = myBind(myFunc, object, 'Dima');
console.log(ewq());