nodejs中的继承

  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原型创建的属性或方法)
    不推荐使用

分享名称:nodejs中的继承
当前URL:http://hxwzsj.com/article/gpcspg.html

其他资讯

Copyright © 2025 青羊区翔捷宏鑫字牌设计制作工作室(个体工商户) All Rights Reserved 蜀ICP备2025123194号-14
友情链接: 成都网站制作 成都网站制作 手机网站制作设计 成都网站制作 盐亭网站设计 高端网站建设 营销型网站建设 响应式网站建设 阿坝网站设计 重庆网站设计 成都网站设计 网站建设 网站制作报价 成都响应式网站建设公司 企业网站建设 成都网站制作 网站建设费用 手机网站制作 成都网站建设公司 成都网站设计 成都h5网站建设 专业网站建设