绫诲拰瀵硅薄
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了绫诲拰瀵硅薄相关的知识,希望对你有一定的参考价值。
鏍囩锛?a href='http://www.mamicode.com/so/1/%e5%88%97%e8%a1%a8' title='鍒楄〃'>鍒楄〃
this static 瀵硅薄 extends div code1.鍩烘湰瀹氫箟鍜屼娇鐢?/p>
1 { 2 class Parent{ 3 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 4 this.name=name; 5 } 6 } 7 var pp = new Parent(鈥榸yn...鈥?span style="color: #000000;">); 8 console.log(鈥樻瀯閫犲嚱鏁板疄渚嬧€?span style="color: #000000;">,pp) 9 }
2.缁ф壙 extends
1 { 2 class Parent{ 3 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 4 this.name=name; 5 } 6 } 7 class Child extends Parent{ 8 9 } 10 console.log(鈥樼户鎵库€?new Child()) 11 }
3.缁ф壙浼犻€掑弬鏁帮紝super
1 { 2 class Parent{ 3 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 4 this.name=name; 5 } 6 } 7 class Child extends Parent{ 8 constructor(name=鈥榗hild鈥?span style="color: #000000;">){ 9 super(name); //super涓槸鐖跺厓绱犵殑灞炴€у垪琛紝濡傛灉瀛愮被闇€瑕佸鍔犲睘鎬э紝super闇€瑕佹斁鍦ㄦ渶鍓嶉潰 10 this.type=鈥榗c鈥?span style="color: #000000;">; 11 } 12 } 13 console.log(鈥樼户鎵夸紶閫掑弬鏁扳€?new Child(),new Child(鈥榟ello鈥?span style="color: #000000;">)) 14 }
4.getter,setter
1 { 2 class Parent{ 3 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 4 this.name=name; 5 } 6 get longName(){ //娉ㄦ剰鏄睘鎬э紝铏界劧鍐欐硶鍍忓嚱鏁?/span> 7 return 鈥榸z鈥?this.name; 8 } 9 set longName(value){ 10 this.name=value 11 } 12 } 13 let vv =new Parent(); 14 console.log(鈥榞etter鈥?span style="color: #000000;">,vv.longName); 15 vv.longName=鈥榸zzzzHello鈥?span style="color: #000000;">; 16 console.log(鈥榮etter鈥?span style="color: #000000;">,vv.longName) 17 }
5.闈欐€佹柟娉曪紝閫氳繃绫昏皟鐢紝鑰屼笉鏄被鐨勫疄渚?/p>
1 { 2 // 闈欐€佹柟娉曪紝閫氳繃绫昏皟鐢紝鑰屼笉鏄被鐨勫疄渚?/span> 3 class Parent{ 4 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 5 this.name=name; 6 } 7 static tell(){ 8 console.log(鈥榯ell鈥?span style="color: #000000;">) 9 } 10 } 11 Parent.tell(); //tell 12 }
6.闈欐€佸睘鎬х洿鎺ュ畾涔夊湪绫讳笂
1 { 2 // 闈欐€佸睘鎬?/span> 3 class Parent{ 4 constructor(name=鈥榸yn鈥?span style="color: #000000;">){ 5 this.name=name; 6 } 7 static tell(){ 8 console.log(鈥榯ell鈥?span style="color: #000000;">) 9 } 10 } 11 12 Parent.type=鈥榯est鈥? //闈欐€佸睘鎬х洿鎺ュ湪绫讳笂瀹氫箟 13 console.log(鈥橀潤鎬佸睘鎬р€?span style="color: #000000;">,Parent.type) 14 }
以上是关于绫诲拰瀵硅薄的主要内容,如果未能解决你的问题,请参考以下文章