Created
December 6, 2014 02:31
-
-
Save teruuuuuu/730601ff480278678d0c to your computer and use it in GitHub Desktop.
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
<!DOCTYPE html> | |
<html> | |
<head> | |
<meta charset="utf-8"> | |
<title>Adapter</title> | |
</head> | |
<body> | |
<script type="text/javascript" src="subclass.js"></script> | |
<script type="text/javascript"> | |
var Banner = Object.subClass({ | |
test:"", | |
init:function(name){ | |
this.name = name; | |
}, | |
showWithParen:function(){ | |
return "(" +this.name + ")"; | |
}, | |
showWithAster:function(){ | |
return "*" +this.name + "*"; | |
}, | |
setName:function(name){ | |
this.name = name; | |
} | |
}); | |
var PrintBanner = Banner.subClass({ | |
printWeak:function(){ | |
return this.showWithParen(); | |
}, | |
printStrong:function(){ | |
return this.showWithAster(); | |
} | |
}); | |
var PrintBanner2 = Object.subClass({ | |
banner:"", | |
init:function(banner){ | |
this.banner = new Banner(banner); | |
}, | |
printWeak:function(){ | |
return this.banner.showWithParen(); | |
}, | |
printStrong:function(){ | |
return this.banner.showWithAster(); | |
} | |
}); | |
var print = new PrintBanner("Hello"); | |
answer(print.printWeak()); | |
answer(print.printStrong()); | |
var print2 = new PrintBanner2("Heelo2"); | |
answer(print2.printWeak()); | |
answer(print2.printStrong()); | |
function answer( desc) { | |
var resultsList = document.getElementById("results"); | |
if (!resultsList) { | |
resultsList = document.createElement('ul'); | |
document.getElementsByTagName('body')[0].appendChild(resultsList); | |
resultsList.setAttribute('id','results'); | |
} | |
var li = document.createElement("li"); | |
li.className = "pass"; | |
li.appendChild(document.createTextNode(desc)); | |
resultsList.appendChild(li); | |
} | |
</script> | |
</body> | |
</html> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment