Created
September 2, 2024 11:49
-
-
Save ppraksa/60509ed90441dae8b6347ea57e3d3898 to your computer and use it in GitHub Desktop.
prototype_inh.js
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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