Skip to content

Instantly share code, notes, and snippets.

@Peleke
Last active May 2, 2016 16:50
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save Peleke/4b6077fe737b33df1934b8eb4bc57c79 to your computer and use it in GitHub Desktop.
Save Peleke/4b6077fe737b33df1934b8eb4bc57c79 to your computer and use it in GitHub Desktop.
"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