[問題] JavaScript的繼承問題

看板Web_Design作者 (飛翔的想法)時間11年前 (2013/06/26 01:22), 編輯推噓0(000)
留言0則, 0人參與, 最新討論串1/2 (看更多)
程式碼是在這裡看到的 http://openhome.cc/Gossip/JavaScript/ClassSimulation.html function Circle(x, y, r) { // 設定物件各自狀態 this.x = x; this.y = y; this.r = r; } . . . function Cylinder(x, y, r, h) { Circle.call(this, x, y, r); // 呼叫父建構式 this.h = h; } // 原型繼承 Cylinder.prototype = new Circle(); // 設定原型物件之constructor為目前建構式 Cylinder.prototype.constructor = Cylinder; // 以下在new時會再建構,不需要留在原型物件上 delete Cylinder.prototype.x; delete Cylinder.prototype.y; delete Cylinder.prototype.r; 我想請問最後3行為什麼要delete掉? 是因為this.x = x這裡就會new出來了嗎? 如果沒有delete掉會浪費記憶體? -- ※ 發信站: 批踢踢實業坊(ptt.cc) ◆ From: 1.172.87.42
文章代碼(AID): #1HoT6_Zw (Web_Design)
文章代碼(AID): #1HoT6_Zw (Web_Design)