<!Doctype html> <html xmlns="http://www./1999/xhtml"> <head> <title>继承</title> <script type="text/javascript"> /* function Animal(){ this.s="animal" } function Cat(){ Animal.call(this) this.name="cat" } var animal= new Animal() var cat= new Cat()
alert(cat.s) //调动 Cat() ==> Animal.call(this) ==> this.s="animal"
*/
function Animal(){ Animal.prototype.s="animal" } function Cat(){ this.name="cat" } Cat.prototype=Animal.prototype var animal= new Animal() var cat= new Cat()
alert(cat.s)
</script>
</head>
<body>
</body>
</html>
|