Attraction attraction0 = new Attraction(0,"校门口","校门口");
Attraction attraction1 = new Attraction(1,"求是楼","教学楼,有自动贩卖机");
Attraction attraction2 = new Attraction(2,"笃实楼","教学楼,有自动贩卖机");
Attraction attraction3 = new Attraction(3,"聚贤楼","学校办公的地方");
Attraction attraction4 = new Attraction(4,"荟贤楼","学校办公的地方");
Attraction attraction5 = new Attraction(5,"济贤楼","学校办公的地方");
Attraction attraction6 = new Attraction(6,"创新楼","可以拿快递,教学楼");
Attraction attraction7 = new Attraction(7,"立业楼","教学楼,有自动贩卖机,有电梯");
Attraction attraction8 = new Attraction(8,"思齐苑","教师宿舍楼");
Attraction attraction9 = new Attraction(9,"明德楼","教学楼,有电梯");
Attraction attraction10 = new Attraction(10,"厚德楼","教学楼,有自动贩卖机");
Attraction attraction11 = new Attraction(11,"三江园","学生饭堂,有百货商店");
Attraction attraction12 = new Attraction(12,"融创楼",".融创楼");
Attraction attraction13 = new Attraction(13,"融新楼","教学楼,可以上电脑课");
```java
switch (co){
case 1:
Menu.Navigation();
attraction0.toString();
break;
重写一个toString方法,然后输出
输出到哪里 你可以在Attraction重新tostring ,然后在构造函数里调用
1. 创建空对象;
var p= {};
2. 设置新对象的__proto__属性指向构造函数的prototype对象;
p.__proto__ = ClassA.prototype; 这里用到了原型链 后面我会写文章做说明
3. 使用新对象调用函数,函数中的this被指向新实例对象(因此可以用new关键字来改变this的指向):
var ceshi=function(name){
this.name=name;
console.log(this)//ceshi {name:"奔驰"}
//ceshi {name:"法拉利"}
}
var car1=new ceshi('奔驰')
var car2=new ceshi('法拉利')
上述代码中 this分别指向car1 和 car2
ClassA.call(p); //{}.构造函数(); 让this变成p
4. 将初始化完毕的新对象地址,保存到等号左边的变量中。