Created
December 18, 2017 10:06
-
-
Save entrptaher/5ce992e53b27c9c2fd750e10068fc12d to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
const skillSet = context => { | |
return { | |
nameSkills: { | |
getName() { | |
return context.name; | |
}, | |
setName(name) { | |
context.name = name; | |
} | |
} | |
}; | |
}; | |
class SecretSkills { | |
constructor(context) { | |
this.context = context; | |
} | |
get nameSkills() { | |
const self = this; | |
return { | |
getName() { | |
return self.context.name; | |
}, | |
setName(name) { | |
self.context.name = name; | |
} | |
}; | |
} | |
} | |
class People { | |
constructor(name) { | |
this.name = name; | |
this.skills = skillSet(this); | |
this.secretSkills = new SecretSkills(this); | |
} | |
} | |
const people = new People("World"); | |
console.log(people.skills.nameSkills.getName()); | |
const people2 = new People("Hello"); | |
console.log(people2.secretSkills.nameSkills.getName()); |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var skillSet = (function (context) { | |
return { | |
nameSkills: { | |
getName: function () { | |
return context.name; | |
}, | |
setName: function (name) { | |
context.name = name; | |
} | |
} | |
}; | |
}); | |
var SecretSkills = /** @class */ (function () { | |
function SecretSkills(context) { | |
this.context = context; | |
} | |
Object.defineProperty(SecretSkills.prototype, "nameSkills", { | |
get: function () { | |
var self = this; | |
return { | |
getName: function () { | |
return self.context.name; | |
}, | |
setName: function (name) { | |
self.context.name = name; | |
} | |
}; | |
}, | |
enumerable: true, | |
configurable: true | |
}); | |
return SecretSkills; | |
}()); | |
var People = /** @class */ (function () { | |
function People(name) { | |
this.name = name; | |
this.skills = skillSet(this); | |
this.secretSkills = new SecretSkills(this); | |
} | |
return People; | |
}()); | |
var people = new People('World'); | |
console.log(people.skills.nameSkills.getName()); | |
var people2 = new People('Hello'); | |
console.log(people2.secretSkills.nameSkills.getName()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment