• 构造方法:


    构造方法:

    		class Student{
    			constructor (name,age){
    				this.name 
    
    =name;
    				this.age=age;
    			}
    			run(){
    				console.log("我会跑");
    			}
    		}
    		let xs = new Student("曹伟",22);
    		console.log(xs);//打印:Student {name: "曹伟", age: 22}。
    		//constructor:实例化那些默认属性。
    		
    		
    		继承:
    		class Teacher extends Student{
    			constructor (name,age,sex){
    				super(name,age);
    				this.sex=sex;
    			}
    			eat(){
    				console.log(this.name 
    
    +"is eating")
    			}
    		}
    		var ls = new Teacher("美女","30","母");
    		console.log(ls);//打印:Teacher {name: "美女", age: "30", sex: "母"}。
    		ls.eat();//打印:老师is eating。
    		//extends:继承。
    		//super:继承属性方法。
    		注释:在构造方法里的super是指反类的构造方法。
    

    		get,set,static:
    		class Student{
    			constructor (name,age){
    				this.name 
    
    =name;
    				this.age=age;
    			}
    			run(){
    				console.log("我会跑");
    			}
    			get xm(){
    				return this.name 
    
    +"123";
    			}
    			set xm(value){
    				this.name 
    
    =value;
    			}
    			static shangxue (){
    				console.log("去读书");
    			}
    		}
    		let xs = new Student("曹伟",25);
    		console.log(xs.xm);
    		xs.xm="骚胖";
    		console.log(xs.xm);
    		Student.shangxue();
    		//get:获取加赋值。
    		//set:设置。
    		//static:静态方法|类方法。
    		//set和get的方法名相同,而且可以同名
    		
    		
    		方法重载|方法覆盖:
    		class Student{
    			constructor (name,age){
    				this.name 
    
    =name;
    				this.age=age;
    			}
    			run(){
    				console.log("我会跑");
    			}
    		}
    		let xs = new Student("曹伟",25);
    		
    		class Teacher extends Student{
    			constructor (name,age,sex){
    				super(name,age);
    				this.sex=sex;
    			}
    			eat(){
    				console.log(this.name 
    
    +"is eating")
    			}
    run(){
    			super.run();
    			console.log("我一直在跑");
    			}
    		}
    		var ls = new Teacher("老师","30","男");
    		ls.run();//我会跑 我一直在跑;
    		
    		注释:虽然子类继承了父类的run方法,但是子类会把父类的方法给覆盖掉,这个就是方法覆盖。
  • 相关阅读:
    xls与csv文件的区别
    青音,经典爱情语录
    win7用户账户自动登录方法汇总
    How to using Procedure found Lead Blocker
    FTS(3) BSD 库函数手册 遍历文件夹(二)
    FTS(3) BSD 库函数手册 遍历文件夹(一)
    DisplayMetrics类 获取手机显示屏的基本信息 包括尺寸、密度、字体缩放等信息
    About App Distribution 关于应用发布
    FTS(3) 遍历文件夹实例
    OpenCV 2.1.0 with Visual Studio 2008
  • 原文地址:https://www.cnblogs.com/GJcaowei/p/7197382.html
Copyright © 2020-2023  润新知