-
Notifications
You must be signed in to change notification settings - Fork 436
/
Copy pathexercise.js
41 lines (31 loc) · 1.08 KB
/
exercise.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
var input = require('../../input')
module.exports = input()
.wrap(function(words, extend) {
function User(title, name) {
this.title = title
this.name = name
console.info('NEW USER: ' + this)
}
User.prototype.displayName = function() {
return this.title + ' ' + this.name
}
User.prototype.toString = function() {
return '[User: '+this.displayName()+']'
}
var BetterUser = extend(User)
console.log('creating new users:')
console.log("new User('Mrs.', 'Alice Smith')")
var alice = new User('Mrs.', 'Alice Smith')
console.log('')
console.log("new BetterUser('Miss', 'Wei Lu')")
var wei = new BetterUser('Miss', 'Wei Lu')
console.log('')
console.log("new BetterUser('Mr.', 'Joe Smith')")
var joe = new BetterUser('Mr.', 'Joe Smith')
console.log('')
//Test inheritance
console.log('Test inheritance')
console.log('wei instanceof BetterUser: ', wei instanceof BetterUser)
console.log('wei instanceof User: ', wei instanceof User)
console.log('wei.displayName === User.prototype.displayName', wei.displayName === User.prototype.displayName)
})