Skip to content

Instantly share code, notes, and snippets.

@felipeblini
Created November 3, 2016 02:22
Show Gist options
  • Save felipeblini/0e2665456c636f374d73e8b80b12a9e2 to your computer and use it in GitHub Desktop.
Save felipeblini/0e2665456c636f374d73e8b80b12a9e2 to your computer and use it in GitHub Desktop.
var MyClass = function() {};
var properties = {
p: {
value: 42,
writable: false,
enumerable: true,
configurable: false
}
};
// cria um objeto herdando o protótipo de MyClass e com propriedas definidas
var obj = Object.create(MyClass.prototype, properties);
console.log(obj.p); // 42
// alterando o valor da propriedade p
obj.p = 1000;
// p continua 42 pois o writable dele está como false
console.log(obj.p); // 42
// deletando a propriedade p
delete obj.p;
// p continua existindo pois configurable foi definida como false
console.log(obj.p); // 42
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment