java的继承结构_javascirpt继承结构设计

本人博客站点:外链网址已屏蔽

场景:有多个应用处理方式类似,一打开应用就先初始化界面信息,然后各自又有各自的业务逻辑处理方式。所以我在这里抽象出来一个基类,多个应用继承这个基类,这里使用prototype(原型)方式实现继承。

//基类

function App(){

}

App.init=function(){

console.log("App init...");

}

App.init();

App.create = function(app){

if (app instanceof App){

app.init();

}

}

//CutFruit

function CutFruit(){

this.init=function(){

console.log("CutFruit init...");

}

this.cut=function(){

console.log("Your finger speed is very fast...");

}

}

//继承App

CutFruit.prototype = new App();

//CatchThief

function CatchThief(){

this.init=function(){

console.log("CatchThief init...");

}

this.fire=function(){

console.log("fire in the hole....");

}

}

//继承App

CatchThief.prototype = new App();

function main(){

var classRF = window[arguments[0]];

App.create(new classRF());

}

main("CutFruit");

main("CatchThief");

(new CutFruit()).cut();

(new CatchThief()).fire();

打印结果:

App init...

CutFruit init...

CatchThief init...

Your finger speed is very fast...

fire in the hole....

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值