-
Notifications
You must be signed in to change notification settings - Fork 1
/
lesson07.js
73 lines (50 loc) · 1001 Bytes
/
lesson07.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
// this and bind
let cat = {}
cat = {
sound: 'meow',
speak: function () {
console.log(this.sound)
}
}
cat.speak()
let speakFunction = cat.speak
speakFunction()
let speakFunctionBind = speakFunction.bind(cat)
speakFunctionBind()
let person1 = {
name: 'Alex'
}
let person2 = {
name: 'Alexis'
}
function namer () {
console.log(this.name)
}
let b1 = namer.bind(person1)
b1()
namer.bind(person1)()
let b2 = namer.bind(person2)
b2()
let number = {
x: 24,
y: 22
}
let count = function () {
console.log(this.x, this.y)
}
count.bind(number)()
// call
var obj = {
num: 2
}
let multiplier = function multiplyBy (number) {
console.log(this.num * number)
}
multiplier.call(obj, 2)
// learnt text templates! hated the + signs!!!
console.log('%s this is test %d', 'text', 5)
let superMultiplier = function multiplyBy (number1, number2, number3) {
console.log(this.num * number1 * number2 * number3)
}
let modifiers = [2, 5, 8]
superMultiplier.apply(obj, modifiers)