Skip to content

Commit 0f77e29

Browse files
committed
create starter file for video 65
1 parent e862050 commit 0f77e29

File tree

1 file changed

+0
-56
lines changed

1 file changed

+0
-56
lines changed

playground/bind-call-apply.html

Lines changed: 0 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -9,63 +9,7 @@
99
</head>
1010

1111
<body>
12-
<p>Hey</p>
13-
<button>Click me</button>
14-
<div class="wrapper">
15-
<p>Hey im in a wrapper</p>
16-
</div>
17-
<script>
18-
const person = {
19-
name: 'Wes Bos',
20-
sayHi() {
21-
console.log(this);
22-
console.log(`hey ${this.name}`);
23-
return `hey ${this.name}`;
24-
}
25-
};
2612

27-
const jenna = { name: 'Jenna' };
28-
29-
const sayHi = person.sayHi.bind({ name: 'Harry' });
30-
31-
// QS Example
32-
// by calling bind against querySelector, we say when the $ function is run, use `document` as the `this` value.
33-
const $ = document.querySelector.bind(document);
34-
const lookFor = document.querySelectorAll.bind(document);
35-
36-
const wrapper = document.querySelector('.wrapper');
37-
const p = wrapper.querySelector('p');
38-
console.log(p);
39-
console.log($('p'));
40-
console.log(lookFor('p'));
41-
42-
const bill = {
43-
total: 1000,
44-
calculate: function (taxRate) {
45-
console.log(this);
46-
return this.total + (this.total * taxRate);
47-
},
48-
describe(mealType, drinkType, taxRate) {
49-
console.log(`Your meal of ${mealType} with a drink of ${drinkType} was ${this.calculate(taxRate)}`);
50-
}
51-
};
52-
53-
const total = bill.calculate(0.13);
54-
const calc = bill.calculate.bind({ total: 500 }, 0.06);
55-
56-
console.log(calc());
57-
const total2 = bill.calculate.call({ total: 500 }, 0.06);
58-
console.log(total2);
59-
60-
const total3 = bill.calculate.apply({ total: 325 }, [0.60]);
61-
console.log(total3);
62-
63-
const myMeal = bill.describe.call(bill, 'pizza', 'beer', 0.13);
64-
console.log(myMeal);
65-
const myMeal2 = bill.describe.apply(bill, ['pizza', 'beer', 0.13]);
66-
console.log(myMeal2);
67-
68-
</script>
6913
</body>
7014

7115
</html>

0 commit comments

Comments
 (0)