|
@@ -0,0 +1,42 @@
|
|
|
|
|
+(function() {
|
|
|
|
|
+ class Person {
|
|
|
|
|
+ /**
|
|
|
|
|
+ * readonly 只读
|
|
|
|
|
+ * static 类本身 而不是类对象
|
|
|
|
|
+ * public 公开
|
|
|
|
|
+ * private 私有的 类内部可以访问
|
|
|
|
|
+ * protected 受保护的 类的内部和子类均可访问
|
|
|
|
|
+ */
|
|
|
|
|
+ name: string;
|
|
|
|
|
+ private age: number;
|
|
|
|
|
+ protected color:string;
|
|
|
|
|
+ constructor(name:string,age:number,color:string) {
|
|
|
|
|
+ this.name = name;
|
|
|
|
|
+ this.age = age;
|
|
|
|
|
+ this.color = color;
|
|
|
|
|
+ }
|
|
|
|
|
+ get age1() {
|
|
|
|
|
+ return this.age;
|
|
|
|
|
+ }
|
|
|
|
|
+ set age1(val) {
|
|
|
|
|
+ this.age = val;
|
|
|
|
|
+ }
|
|
|
|
|
+ getValue() {
|
|
|
|
|
+ return this.age + 10;
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ class Child extends Person {
|
|
|
|
|
+ look() {
|
|
|
|
|
+ console.log(this.color)
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ let p = new Person("孙悟空",20,'红色');
|
|
|
|
|
+ let c = new Child('图图',2,'白色');
|
|
|
|
|
+ p.age1 = 30;
|
|
|
|
|
+ console.log(p.age1)
|
|
|
|
|
+ // console.log(p.age);
|
|
|
|
|
+ // console.log()
|
|
|
|
|
+ c.look();
|
|
|
|
|
+ console.log(p.getValue())
|
|
|
|
|
+ // console.log(c.color);
|
|
|
|
|
+})()
|