JS类的prototype指向到新对象后,其原型为新对象么?求教

kinghome kinghome 墨衍会员 · AI 创作全网分发 墨衍智能分发 通过墨衍一键同步至各平台 可同步平台 CSDN微信公众号微博知乎掘金百家号博客园抖音小红书 你的文章也可以这样分发 墨衍会员 ¥399起/年,写一次发全网 我也要 + 加入社区

var viewBasic = {
container:"#data-box",
options:{
option:null,
product_type:'pc',
list_type:'harvesting',
resource_type:'tmr',
Period_time:null
}
};

function tickerPage(){
this.url = '';
this.columns=['AUTO','LIFE'];
this.players=[null,null];
this.scrolls=[null,null];
};

tickerPage.prototype = viewBasic;
tickerPage.prototype.init = function(){alert('AAAA')};

function statusPage(){
this.beforeStart = null;
this.afterEnd = null;
this.url='';
}
statusPage.prototype = viewBasic;
statusPage.prototype.init = function(){alert('BBBB')}


function view(){
this.ticker = new tickerPage()
this.status = new statusPage()
};
view.prototype = viewBasic;
view.prototype.show = function(){
var o = this;
switch(o.options.option){
case "ticker":
o.ticker.init();
break;
case "status":
o.status.init();
break;
}
}
window.onload=function(){
viewBasic.options.option = "ticker";
var myview = new view();
myview.show();
}


为何这里输出的是 BBB 而不是 AAA
...全文
评论 1
收藏 已收藏
分享
返回顶部
kinghome
JavaScript 87,984 成员 224,681 内容