forked from jsmapr1/simplifying-js
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathprototypes.js
More file actions
34 lines (29 loc) · 764 Bytes
/
Copy pathprototypes.js
File metadata and controls
34 lines (29 loc) · 764 Bytes
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
/* eslint-disable func-names */
// START:instance
function Coupon(price, expiration) {
this.price = price;
this.expiration = expiration || 'two weeks';
}
const coupon = new Coupon(5, 'two months');
coupon.price;
// 5
// END:instance
// START:prototype
Coupon.prototype.getExpirationMessage = function () {
return `This offer expires in ${this.expiration}.`;
};
coupon.getExpirationMessage();
// This offer expires in two months.
// END:prototype
// START:extend
class FlashCoupon extends Coupon {
constructor(price, expiration) {
super(price);
this.expiration = expiration || 'two hours';
}
getExpirationMessage() {
return `This is a flash offer and expires in ${this.expiration}.`;
}
}
// END:extend
export { Coupon, FlashCoupon };