日期:2014-05-16 浏览次数:20463 次
<html>
<head>
<script type="text/javascript">
function Parent(username) {
this.username = username;
this.sayHello = function() {
alert(this.username);
}
}
function Child(username, password) {
//下面三行代码时重点
this.method = Parent;
this.method(username);
delete this.method;
this.password = password;
this.sayWorld = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123");
parent.sayHello();
child.sayHello();
child.sayWorld();
</script>
</head>
<body>
</body>
</html><html>
<head>
<script type="text/javascript">
function Parent(username) {
this.username = username;
this.sayHello = function() {
alert(this.username);
}
}
function Child(username, password) {
Parent.call(this, username);
this.password = password;
this.sayWorld = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123");
parent.sayHello();
child.sayHello();
child.sayWorld();
</script>
</head>
<body>
</body>
</html><html>
<head>
<script type="text/javascript">
function Parent(username) {
this.username = username;
this.sayHello = function() {
alert(this.username);
}
}
function Child(username, password) {
Parent.apply(this, new Array(username));
this.password = password;
this.sayWorld = function() {
alert(this.password);
}
}
var parent = new Parent("zhangsan");
var child = new Child("lisi", "123");
parent.sayHello();
child.sayHello();
child.sayWorld();
</script>
</head>
<body>
</body>
</html><html>
<head>
<script type="text/javascript">
function Parent() {
}
Parent.prototype.hello = "hello";
Parent.prototype.sayHello = function() {
alert(this.hello);
}
function Child(username, password) {
}
Child.prototype = new Parent();
Child.prototype.world = "world";
Child.prototype.sayWorld = function() {
alert(this.world);
}
var child = new Child();
child.sayHello();
child.sayWorld();
</script>
</head>
<body>
</body>
</html><html>
<head>
<script type="text/javascript">
function Parent(hello) {
this.hello = hello;
}
Parent.prototype.sayHello = function() {
alert(this.hello);
}
function Child(hello, world) {
Parent.call(this, hello);
this.world = world;
}
Child.prototype = new Parent();
Child.prototype.sayWorld = function() {
alert(this.world);
}
var child = new Child("hello", "world");
child.sayHello();
child.sayWorld();
</script>
</he