typescript (iii) Class

  Create a class and inherit the es5

               Animal function (obj) { 
			this.name = obj.name 
			this.type = obj.type 
			this.log = function () { 
				the console.log (the name of this animal is `$ {this.name}, belonging to $ {this. } `type) 
			} 
		} 
		function Dog (obj) { 
			Animal.call (the this, obj) 
			this.sex = obj.sex 
			this.dogSay = function () { 
				this.log () 
				the console.log (` Dog: this animal name is $ {this.name}, {this.type} `belong $) 
			} 
		} 
		const daHuang = new new dog ({name: 'rhubarb', type: 'canine', sex: 'male dogs'}) 
		Console. log (daHuang) 
		daHuang.dogSay ()    

   Creating es6 in classes and inheritance

               Animal {class 
			constructor (obj) { 
				this.name = obj.name, 
				this.type = obj.type 
			} 
			log () { 
				the console.log (the name of this animal is `$ {this.name}, belonging to $ {this. } `type) 
			} 
		} 
		class Dog the extends animal { 
			constructor (OBJ1) { 
				Super (OBJ1) 
				this.sex = obj1.sex 
			} 
			dogSay () { 
				super.log () 
				the console.log (` Dog: the animals name $ {this.name}, {this.type belonging} `$) 
			} 
		} 
		const = daHuang new new dog ({name: 'rhubarb', type: 'canine', sex: 'male dogs'}) 
		the console.log (daHuang ) 
		daHuang.dogSay ()

     Not to call super constructor es6 in words of this can not be used here is to give the parent to inherit a reference animal passaged with super (OBJ1);

Guess you like

Origin www.cnblogs.com/mufc/p/11227148.html