JavaScript object and prototype

JavaScript Object and prototype:

These two different codes will produce the same output

var cat = {name: 'Fluffy'}

var cat = Object.create(Object.prototype, { 
 name: { 
  value: "Fluffy", 
  enumerable: true, 
  writable: true, 
  configurable: true

Follow the below code to get the same output, and the same can be configured

Object.getOwnPropertyDescriptor(cat, 'name')

Object.defineProperty(cat, 'name', {writable: false})
Object.defineProperty(cat, 'name', {enumerable: false})


Object.defineProperty(cat, 'fullName', 
 get: function () { return + ' ' +},
 set: function () {
  var nameParts = values.split(' '); = nameParts[0]; = nameParts[1];

var arr = ['aa', 'bb']
Object.defineProperty(arr, 'last', { get: function () {return this[this.lenght-1]}})

Object.defineProperty(Array.prototype, 'last', { get: function () {return this[this.lenght-1]}})

var last = arr.last

function Cat (name, color)  { = name;
 this.color = color

var fluffy = new Cat('fluffy', 'white')

var muffine = new Cat('Muffin', 'Brown')

fluffy.age = 5


4 thoughts on “JavaScript object and prototype”

  1. What’s up, after reading this amazing article i am as well glad to share my familiarity here with friends.

  2. I feel this is one of the such a lot significant info for
    me. And i’m glad reading your article. But want to observation on few general issues, The web site style is wonderful, the articles is actually excellent : D.
    Excellent job, cheers

Leave a Reply

Your email address will not be published. Required fields are marked *