From f4c0a3ddb77a3cc07a1d280577037a0144567038 Mon Sep 17 00:00:00 2001 From: JavaSDragon <33486797+JavaSDragon@users.noreply.github.com> Date: Thu, 25 Jan 2018 16:42:45 +0300 Subject: [PATCH] promise promise --- classTask.js | 39 +++++++++++++++++++++++++++++++++++++++ 1 file changed, 39 insertions(+) create mode 100644 classTask.js diff --git a/classTask.js b/classTask.js new file mode 100644 index 0000000..137f329 --- /dev/null +++ b/classTask.js @@ -0,0 +1,39 @@ +class Animal { + constructor(type,age=2){ + this.type=type; + this.age=age; +} +getType(){ + return `Animal type:${this.type}`; +} +getAge(){ + return `Animal age:${this.age}`; +} +getInfo(){ + return this.getType()+ ', ' +this.getAge(); +} +} +class Cat extends Animal{ + constructor(type,age,color='black'){ + super(type,age); + this.color=color; + } + getColor(){ + return `Cat color:${this.color}`; + } + getInfo(){ + return super.getInfo()+ ', ' +this.getColor(); + } + getNameAsync(name){ + return new Promise(function(resolve,reject){ + setTimeout(function(){ + resolve(name); + },5000); + }); + } +} +task=new Animal('Cat',3); +task1=new Cat('Mike',undefined,'red'); +console.log(task.getInfo()); +console.log(task1.getInfo()); +task1.getNameAsync('Vasya').then(function(name){console.log(name)}); \ No newline at end of file