SOURCE

console.log('---------------例1---------------')
var car={
    name:"car1",
    age:5,
    run_distance:0,
    move:function(from,to,distance){
        console.log("car从"+from+"到"+to+"开始行驶");
        console.log("行驶距离为"+distance);
        this.run_distance+=distance
    },
    getDistance:function(){
        console.log("总行驶距离为"+this.run_distance)
    }
}
car.move("北京","天津",500);
car.getDistance();
car.move("天津","广州",3500);
car.getDistance();

console.log('---------------例2--------------------')
circle=function(r){
    this.radius=r
    this.area=function(){
        console.log("半径为"+this.radius+"的圆面积为")
        return Math.PI*this.radius*this.radius
    }
}
circle1=new circle(5)
console.log(circle1.area())
circle2=new circle(200)
console.log(Math.ceil(circle2.area()))

console.log('----------------例3-------------------')
Rectangle=function(width,height){
    this.width=width;
    this.height=height;
    this.area=function(){
        console.log("矩形现宽为"+this.width+"高为"+this.height);
        return this.width*this.height
    }
    this.addWidth=function(w_add){
        this.width=this.width+w_add
    }
    this.addHeight=function(h_add){
        this.height=this.height+h_add
    }
}
Rectangle1=new Rectangle(30,90);
console.log("矩形面积为:"+Rectangle1.area())
Rectangle1.addWidth(20)
console.log("矩形面积为:"+Rectangle1.area())
Rectangle1.addHeight(100)
console.log("矩形面积为:"+Rectangle1.area())
Rectangle1.addHeight(100)
console.log("继续增加高度后矩形面积为:"+Rectangle1.area())
Rectangle1.addWidth(100)
console.log("继续增加宽度后矩形面积为:"+Rectangle1.area())
console 命令行工具 X clear

                    
>
console