js通過原型鏈實現繼承
阿新 • • 發佈:2020-12-18
技術標籤:CesiumJS
function A(name) { this.name = name; } A.prototype = { show() { console.log(this.name); } } function B(name) { this.name = name; } B.prototype = Object.create(A.prototype); function C(name) { this.name = name; } C.prototype = Object.create(A.prototype); console.log(new B() instanceof A); //列印結果:true console.log(new C() instanceof A); //列印結果:true
總結:通過共用A的原型,來實現對A的繼承
FR:徐海濤(hunk Xu)
QQ技術交流群:386476712