Last active
August 11, 2016 02:18
-
-
Save tyaslab/619c09fc19159d239b077d20fee9a59e to your computer and use it in GitHub Desktop.
javascript advance
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
function Mammal() {}; | |
Mammal.prototype.sayHello = function() { | |
alert("Hello from mammal"); | |
} | |
// inheritance step 1 | |
function Cat() { | |
Mammal.call(this); | |
} | |
// inheritance step 2 (extends) | |
Cat.prototype = Object.create(Mammal.prototype); | |
// inheritance step 3 (constructor) | |
Cat.prototype.constructor = Cat; | |
Cat.prototype.sayHello = function() { | |
// polymorphism | |
Mammal.prototype.sayHello.call(this); | |
alert("Hello from cat"); | |
} | |
var cat = new Cat(); | |
cat.sayHello(); |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
var promise = function() { | |
return new Promise(function(resolve, reject) { | |
setTimeout(function() { | |
document.getElementById("promise").innerHTML = "yay!"; | |
resolve(); | |
}, 2000); | |
}); | |
} | |
promise().then(function() { | |
document.getElementById("wrapper").innerHTML = "okay done!"; | |
}, function() { | |
}); | |
document.getElementById("wrapper").innerHTML = "i will be disappeared!"; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment