Skip to content

Instantly share code, notes, and snippets.

@ppraksa
Created September 2, 2024 11:49
Show Gist options
  • Select an option

  • Save ppraksa/60509ed90441dae8b6347ea57e3d3898 to your computer and use it in GitHub Desktop.

Select an option

Save ppraksa/60509ed90441dae8b6347ea57e3d3898 to your computer and use it in GitHub Desktop.
prototype_inh.js
var shape = {
type: "",
getType: function () {
return this.type;
},
};
function Triangle(a, b, c) {
this.type = "triangle";
this.a = a;
this.b = b;
this.c = c;
}
Triangle.prototype = shape;
Triangle.prototype.constructor = Triangle;
Triangle.prototype.getPerimeter = function () {
return this.a + this.b + this.c;
};
var t = new Triangle(1, 2, 3);
console.log(shape.isPrototypeOf(t));
console.log(t.getPerimeter());
console.log(t.getType());
console.dir(t.constructor);
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment