Skip to content

Instantly share code, notes, and snippets.

@victorvhpg
Last active November 11, 2016 00:48
Show Gist options
  • Save victorvhpg/e0bcffe12a8ce4ffc9f55a894e7dad4d to your computer and use it in GitHub Desktop.
Save victorvhpg/e0bcffe12a8ce4ffc9f55a894e7dad4d to your computer and use it in GitHub Desktop.
let Pessoa = (function() {
"use strict";
const Pessoa = function(name) {
//valida se foi chamada com new
if (typeof new.target === "undefined") {
throw new Error("Somente deve ser chamada com new.");
}
this.name = name;
}
Object.defineProperty(Pessoa.prototype, "getNome", {
value: function() {
if (typeof new.target !== "undefined") {
throw new Error("NÃO deve ser chamada com new.");
}
console.log(this.name);
},
enumerable: false,
writable: true,
configurable: true
});
return Pessoa;
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment