-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathnode-harmony.js
116 lines (58 loc) · 2.6 KB
/
node-harmony.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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
'use strict';
// =============================================================================
// Function Constructors
// =============================================================================
// function Human ( firstName, lastName ) {
// this.firstName = firstName || 'John';
// this.lastName = lastName || 'Doe';
// }
// Human.prototype.greet = function () {
// return ( 'Hi, my name is ' + this.firstName + ' ' + this.lastName )
// };
// // static method
// Human.type = function () { return 'human' };
// var human = new Human( 'Anakin', 'Skywalker' )
// console.log( human.greet() )
// =============================================================================
// Prototypal Inheritance
// =============================================================================
// function SuperHuman ( firstName, lastName, alias, superpowers ) {
// Human.call(this, firstName, lastName );
// this.alias = 'Spider-man' || 'unknown';
// this.superpowers = superpowers || [];
// };
// SuperHuman.prototype = Object.create( Human.prototype );
// SuperHuman.prototype.constructor = SuperHuman;
// SuperHuman.prototype.greet = function () { return ( 'Hi, I am ' + this.alias + '!' ) };
// SuperHuman.prototype.revealIdentity = function () {
// var greet = ( Human.prototype.greet.call(this) + ' a.k.a. ' + this.alias );
// return ( greet + ' and I am a ' + SuperHuman.type() + '.' );
// };
// SuperHuman.prototype.useSuperpower = function () {
// return ( this.alias + ' uses the ' + this.superpowers[0] + '!' )
// };
// SuperHuman.type = function () { return 'superhuman' };
// var spiderMan = new SuperHuman( 'Peter', 'Parker', 'Spider-Man', ['web attack'])
// console.log( spiderMan.greet() )
// console.log( spiderMan.revealIdentity() )
// console.log( spiderMan.useSuperpower() )
// =============================================================================
// Getters & Setters
// =============================================================================
// Object.defineProperty(Human.prototype, 'fullName', {
// get: function () {
// return ( this.lastName + ', ' + this.firstName );
// }
// });
// Object.defineProperty(Human.prototype, 'occupation', {
// get: function () {
// return ( 'Occupation: ' + this._occupation );
// },
// set: function ( occupation ) {
// return this._occupation = occupation;
// }
// });
// var human = new Human()
// console.log( human.fullName ) // Doe, John
// human.occupation = 'Front-end Developer'
// console.log( human.occupation ) // Occupation: Front-end Developer