Last active
May 2, 2016 16:50
-
-
Save Peleke/4b6077fe737b33df1934b8eb4bc57c79 to your computer and use it in GitHub Desktop.
This file contains 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
"use strict"; | |
class User { | |
constructor (private _name : string, | |
private _email : string) {} | |
get name () : string { return this._name; } | |
get email () : string { return this._email; } | |
// Return function via getter | |
get speak () : (() => void) { | |
return function _speak () { | |
console.log(`I am ${this.name}!`); | |
} | |
} | |
} | |
const peleke = new User ('Peleke', 'resil.design@gmail.com'); | |
peleke.speak(); // 'I am Peleke!' | |
try { | |
User.prototype.speak = null; // | |
} catc (err) { | |
// TypeError | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment