JSFiddle - React, Tailwind, and code Playground

by Jagrati Tomar

JavaScript

var obj = {
  "a" : 1,
  "b" : 2
}

// object.assign one or more objects

var newObj = Object.assign({}, obj, {
 "data" : "jagrati"
})

function foo () {
	this.foo = "fooo"
}

var a = Object.create({foo : 1}, {
	baz : {
  	value : 12
  },
  bar : {
  	value : 13,
    enumerable : true // showing properties in for.. in
  }
})
// Inheritance

var superClass = function () {
	this.x = 0
  this.y = 0
}

superClass.prototype.move = function (x, y) {
	this.x += x
  this.y += y
}

var rectangle = function () {
	superClass.call(this)
}

rectangle.prototype = Object.create(superClass.prototype)
rectangle.prototype.constructor = rectangle

o = Object.create({}, {
  // foo is a regular 'value property'
  foo: {
    writable: true,
    configurable: true,
    value: 'hello',
    enumerable : true
  },
  // bar is a getter-and-setter (accessor) property
  bar: {
    configurable: false,
    get : function() { return 10; },
    set :  function(value) {
      console.log('Setting `o.bar` to', value);
    }
    }})


Object.defineProperty(o, "name", {
	get : function() {return "jagrati"},
  set : function(name) { console.log(name)},
  enumerable : true
})

//obj2 = Object.freeze(obj)
/* Object.defineProperty(obj, 'name', {})
Object.defineProperties(obj, 'name', {
  property1 : {
    // descriptor
  }
}) */

console.log(Object.keys(obj))

console.log(obj.hasOwnProperty("foo"))

console.log(o)