对象奔驰E2000

 

 

<script>
    window.onload = function (ev) {
        // 调用对象前先创建
        // 2
        var vcar=new Car("奔驰","E2000",50,2);
        // 3
        vcar.startup();
        vcar.Startengine();
        vcar.changeSpeed();
        vcar.swerve();
        vcar.stop();
        vcar.Turnofftheengine();
    }

//1
    function Car(make, model, currentSpeed, displacement) {
       // this.make = "奔驰";
       // this.model = E2000;
       var currentSpeed = currentSpeed;
      //  this.displacement = 2;
        //启动引擎
        this.Startengine = function () {
            var speed =currentSpeed;
            document.write("<br>"+"启动引擎:"+speed);
        };
        //启动
        this.startup = function () {
            document.write("启动:0");
        };
        //加速
        this.changeSpeed = function () {
            var speed =currentSpeed*2;
            document.write("<br>"+"加速:"+speed);
            ///return speed;
        };
      // car.changeSpeed();
        //转向
        this.swerve = function () {
            var speed =currentSpeed/5*2;
            document.write("<br>"+"转向:"+speed);
        };
        //刹车
        this.stop = function () {
            var speed =0;
            document.write("<br>"+"刹车:"+speed);
        };
        //关闭引擎
        this.Turnofftheengine = function f() {
            var speed =currentSpeed/5/2;
            document.write("<br>"+"关引擎:"+speed);
        };
    }
</script>

  

 

posted @ 2018-04-12 10:05  麦克斯-侯  阅读(311)  评论(0编辑  收藏  举报
百纵科技