OOJS

JavaScript

function a(){
	this.name = 'Samar', 
	this.age = 23
  };
a.prototype.gen="Male";
function b(){
	a.call(this);
	this.add= 'Balasore'
  };
b.prototype= Object.create(a.prototype);
b.prototype.constructer= b;
b.prototype.gen="feMale";
var bO= new b();
var aO= new a();
console.log("name is property of a" + a.hasOwnProperty('name'));
console.log("name is property of b" + b.hasOwnProperty('name'));
console.log("add is property of a" + b.hasOwnProperty('add'));
console.log(aO.name + bO.name);
console.log(aO.gen + bO.gen);
var aPro= Object.getPrototypeOf(a);
var bPro= Object.getPrototypeOf(b);
console.log(aPro);
console.log(bPro);
//
console.log(bO instanceof b);
console.log(bO instanceof a);
console.log(aO instanceof a);
console.log(aO instanceof b);

//

//************************************
function Pasta(grain, width) {
    this.grain = grain;
    this.width = width;
}
// Create an object from the pasta constructor.
var spaghetti = new Pasta("wheat", 0.2);

// Obtain the prototype from the object.
var proto = Object.getPrototypeOf(spaghetti);

// Add a property to the prototype and validate that
// the original object has the property.
//Pasta.prototype.foodgroup = "carbohydrates";
proto.foodgroup="carbohydrates";
console.log(spaghetti.foodgroup + " ");
console.log(proto===Pasta.prototype);
console.log(Object.getPrototypeOf(new Pasta('rice',4))===Pasta.prototype);

console.log('&&&&&&&&&&&&&&&&');
var proto = {};
var obj = Object.create(proto);
console.log(Object.getPrototypeOf(obj) === proto); // true

var Car2 = Object.create(null); //this is an empty object, like {}
Car2.prototype = {
  getInfo: function() {
    return 'A ' + this.color + ' ' + this.desc + '.';
  }
};
 
var car2 = Object.create(Car2.prototype, {
  //value properties
  color:   { writable: true,  configurable:true, value: 'red'},
  getColor:{
  		configurable:true, 
  		get : function(){return this.color.toUpperCase();},
      set: function(value){ if(value=='blue'){alert('hi')}
      this.color =...