Skip to content

Instantly share code, notes, and snippets.

@greenlikeorange
Last active August 29, 2015 14:10
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save greenlikeorange/2022cb57ceb0a35c97c5 to your computer and use it in GitHub Desktop.
Save greenlikeorange/2022cb57ceb0a35c97c5 to your computer and use it in GitHub Desktop.
CONST Example under ES6
function CONST (obj, key, value){
Object.defineProperty(obj, key, {
enumerable: false,
configurable: false,
writable: false,
value: value
});
}
function Person (name, birthday) {
this.name = name;
CONST(this, 'birthday', birthday);
}
// Create Person
var Thuya = new Person("Thuya", "31,Jan");
// Reassign
Thuya.birthday = "3,Feb";
// Checking
console.log(Thuya.birthday === "3,Feb");
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment