Skip to content

Instantly share code, notes, and snippets.

@samundrak
Created May 10, 2016 19:39
Show Gist options
  • Save samundrak/1fd66c6c27aef45cc28655d9529a0ff3 to your computer and use it in GitHub Desktop.
Save samundrak/1fd66c6c27aef45cc28655d9529a0ff3 to your computer and use it in GitHub Desktop.
//By object Create
//We can make some props non enumerable
//We can make some props non writable and non configurable
var cat = Object.create(Object.prototype,{
name : {
value :'samundra',
enumerable : true,
writable : true,
configurable: true
},
lastname :{
value : 'khatri',
enumerable : true,
writable :true,
configurable : true
}
});
//Object.freeze - To freeze object from overriden
//Object.getOwnPropertyDescriptor - To see the description of property of object
//Object.defineProperty - To define defination of property of object
//Object.keys - Collection of keys of object
function Cat(name,color){
this.name = name;
this.color = color;
}
Cat.prototype.age = 12;
var fluffy = new Cat('fluffy','white');
var honey = new Cat('honey','singh');
console.log(Cat.prototype);
console.log(fluffy.__proto__);
console.log(honey.__proto__);
fluffy.age = 10;
console.log(fluffy.age);
console.log(honey.age);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment