资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

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中的继承
文章位置:http://cdkjz.cn/article/gpcspg.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220