直播app开发搭建,web前端JS中的继承方式

直播app开发搭建,web前端JS中的继承方式

ES5

1
//ES5中的写法一<br> <br>    function Phone(color){<br>        this.color = color;<br>        this.show = function(){<br>            console.log("你喜欢看的颜色是:"+this.color);<br>        }<br>    }<br>    function Vivo(color){<br>        Phone.call(this,color);<br>    }<br>    var vivo = new Vivo("黄色");<br>    vivo.show();<br> <br>//这里主要利用了call()方法改变this指向<br>    写法二,原型链继承<br> <br>    function Person(name,age){<br>        this.name = name;<br>        this.age = age;<br>        this.eat = function(){<br>            console.log(name + "很能吃");<br>        }<br>    }<br> <br>    function Player(type){<br>        this.type = type;<br>    }<br>    Player.prototype = new Person("简自豪");<br>    var player = new Player();<br>    player.eat();<br> <br>    //写法三,拷贝继承<br>    function MingXing(name){<br>        this.name = name;<br>        this.sing = function(){<br>            console.log(this.name + "会唱歌");<br>        }<br>    }<br>    var jack = {<br>        extend:function(obj){<br>            for(var val in obj){<br>                this[val] = obj[val];<br>            }<br>        }<br>    };<br>    jack.extend(new MingXing("陈明"));<br>    jack.sing();<br> <br>    //写法四,组合继承<br>    function Car(color){<br>        this.color = color;<br>    }<br> <br>    function Passat(color,type){<br>        Car.call(this,color);<br>        this.type = type;<br>    }<br>    Passat.prototype = new Car();<br>    Passat.prototype.run = function(){<br>        console.log(this.color+this.type+"会跑");<br>    }<br>    var passat = new Passat("黑色","帕撒特");<br>    passat.run();

​ES6

1
class Fu{<br>        constructor(x,y){<br>            this.x = x;<br>            this.y = y;<br>        }<br>        show(){<br>            console.log("x = "+this.x+",y = "+this.y);<br>        }<br>    }<br>    class Zi extends Fu{<br>        constructor(x,y){<br>            super(x,y);<br>        }<br>    }<br>    const zi = new Zi(1,2);<br>    zi.show();

 

以上就是直播app开发搭建,web前端JS中的继承方式, 更多内容欢迎关注之后的文章

 

posted @   云豹科技-苏凌霄  阅读(9)  评论(0编辑  收藏  举报
相关博文:
阅读排行:
· 分享一个免费、快速、无限量使用的满血 DeepSeek R1 模型,支持深度思考和联网搜索!
· 基于 Docker 搭建 FRP 内网穿透开源项目(很简单哒)
· ollama系列01:轻松3步本地部署deepseek,普通电脑可用
· 25岁的心里话
· 按钮权限的设计及实现
历史上的今天:
2022-06-07 短视频商城系统,首屏加载loading动画界面和路由跳转动画
2022-06-07 app直播源码,实现进度条自增长及渐变样式
2022-06-07 视频直播源码,css实现图片对角边框线
点击右上角即可分享
微信分享提示