作者flyingIdea (飞翔的想法)
看板Web_Design
标题[问题] JavaScript的继承问题
时间Wed Jun 26 01:22:05 2013
程式码是在这里看到的
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