forked from zoltantothcom/Design-Patterns-JavaScript
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathstructural_proxy.js
More file actions
53 lines (44 loc) · 939 Bytes
/
structural_proxy.js
File metadata and controls
53 lines (44 loc) · 939 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
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
const PROXY = {
id: 'proxy',
name: 'Proxy',
type: 'structural',
hint: 'An object representing another object',
definition: `Provide a surrogate or placeholder for another object to control access to it.`,
when: ``,
codeES5: `function Car() {
this.drive = function() {
return 'driving';
};
}
function CarPattern(driver) {
this.driver = driver;
this.drive = function() {
if (driver.age < 18) return 'too young to drive';
return new Car().drive();
};
}
function Driver(age) {
this.age = age;
}
module.exports = [Car, CarPattern, Driver];`,
codeES6: `class Car {
drive() {
return 'driving';
}
}
class CarPattern {
constructor(driver) {
this.driver = driver;
}
drive() {
return this.driver.age < 18 ? 'too young to drive' : new Car().drive();
}
}
class Driver {
constructor(age) {
this.age = age;
}
}
export { Car, CarPattern, Driver };`
};
export default PROXY;