JSFiddle - React, Tailwind, and code Playground

by krishna chaitanya nalluri

JavaScript

function ParentWithStatic() {}

ParentWithStatic.startPosition = { x: 0, y:0 }
ParentWithStatic.getStartPosition = function getStartPosition() {
  return this.startPosition
} 

function Child(x, y) {
  this.position = {
    x: x,
    y: y
  }
}

Child.prototype = Object.create(ParentWithStatic.prototype)
Child.prototype.constructor = Child

Child.prototype.getOffsetByInitialPosition = function getOffsetByInitialPosition() {
  let position = this.position
  let startPosition = this.constructor.getStartPosition() // error undefined is not a function, since the constructor is Child
  return {
    offsetX: startPosition.x - position.x,
    offsetY: startPosition.y - position.y
  }
};

console.log("startPosition", Child.getOffsetByInitialPosition)