nodejs中的继承

发布时间:2020-06-16 10:31:32 作者:Lee_吉
来源:网络 阅读:648
  1. node(不推荐使用):
    a. 代码:
    var inherits = require("util").inherits; 
    function a(){
    this.name = "lee"
    }
    a.prototype.sex = "male"
    function b(){
    this.color = "red"
    }
    b.prototype.height = "168"
    function c(){
    }
    inherits(c,a)
    inherits(c,b)
    var c = new c()
    console.log(c.height)
    console.log(c.sex)
    console.log(c.name)

    b. 输出:

    168
    undefined
    undefined
  2. ecmascript(原生javascript):
    a. 代码:
    function a(){
    this.name = "lee"
    }
    a.prototype.sex = "male"
    function b(){
    this.color = "red"
    }
    b.prototype.height = "168"
    function c(){
    }
    c.prototype = new a()
    c.prototype = new b()
    var c = new c()
    console.log(c.height)
    console.log(c.sex)
    console.log(c.name)

    b. 输出:

    168
    undefined
    undefined
  3. 说明:
    1、只支持单继承
    2、不能作用于类本身的属性或方法(只支持prototype原型创建的属性或方法)
    不推荐使用
推荐阅读:
  1. js中的继承
  2. C++多重继承中的虚继承举例

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

nodejs 继承 j

上一篇:Gin中实现HTTP和Basic Auth的方法

下一篇:再看hadoop RPC

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》