-
Notifications
You must be signed in to change notification settings - Fork 28
/
Copy pathmultiple-extends.js
50 lines (42 loc) · 1.04 KB
/
multiple-extends.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
import { ObjectModel } from "objectmodel";
const User = ObjectModel({
email: String, // mandatory
name: [String] // optional
});
const Person = ObjectModel({
name: String,
female: Boolean
});
const Order = ObjectModel({
product: {
name: String,
quantity: Number
},
orderDate: Date
});
const Client = Person.extend(User, Order, { store: String });
Client.prototype.sendConfirmationMail = function() {
return (
this.email +
": Dear " +
this.name +
", thank you for ordering " +
this.product.quantity +
" " +
this.product.name +
" on " +
this.store
);
};
console.log(Object.keys(Client.definition));
// ["name", "female", "email", "product", "orderDate", "store"]
const joe = new Client({
name: "Joe",
female: false,
email: "joe@email.net",
product: { name: "diapers", quantity: 100 },
orderDate: new Date(),
store: "daddy.net"
});
document.write(joe.sendConfirmationMail());
// joe@email.net: Dear Joe, thank you for ordering 100 diapers on daddy.net