重庆分公司,新征程启航

为企业提供网站建设、域名注册、服务器等服务

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://cqcxhl.cn/article/gpcspg.html

其他资讯

在线咨询
服务热线
服务热线:028-86922220
TOP