JSFiddle - React, Tailwind, and code Playground

by Yogesh Rathod

JavaScript

//prototype inheritance with out using new

var rectangle = {
     create: function (width, height) {
          var self = Object.create(this);
          self.height = height;
          self.width = width;
          return self;
      },
      area: function () {
          return this.width * this.height;
     }
 };
 
// var rect = rectangle.create(5, 10);
 
 var square = Object.create(rectangle);
 
 square.create = function (side) {
    return rectangle.create.call(this, side, side);
 };
 
 var sq = square.create(5);
 
 alert(sq.area());

 //alert(rect.area());
 
 var base = { 
 name1: 'Yogesh',
 GetName:function(){ return this.name1;}
 }
 

 var child = Object.create(base,{name1:{value:'Sunita'}});
 //alert(child.GetName());