• λ我爱Aspx >> Asp.Net >> Javascript综合使用
  • Javascript综合使用

  • :未知  Դ:internet  :2007-5-20 16:46:54  ؼ:javascript
  • JavaScript中也可以实现私有属性,而且JavaScript也能像C++和Java一样支持基于类的继承方法。为了展示这些是怎样实现的,下面说明如何转换前面使用Vehicle、SportsCar和CementTruck对象的例子,从而使用信息隐藏和继承的新模式。代码清单5-5列出了新的对象定义。

    代码清单5-5 classicalInheritance.js

    function Vehicle() {

    var wheelCount = 4;

    var curbWeightInPounds = 4000;

    this.getWheelCount = function() {

    return wheelCount;

    }

    this.setWheelCount = function(count) {

    wheelCount = count;

    }

    this.getCurbWeightInPounds = function() {

    return curbWeightInPounds;

    }

    this.setCurbWeightInPounds = function(weight) {

    curbWeightInPounds = weight;

    }

    this.refuel = function() {

    return "Refueling Vehicle with regular 87 octane gasoline";

    }

    this.mainTasks = function() {

    return "Driving to work, school, and the grocery store";

    }

    }

    function SportsCar() {

    this.refuel = function() {

    Ҷƪл˵?
  • һƪ使用XMLHttpRequest对象
    һƪJavaScript中基于类的继承