Skip to content

Instantly share code, notes, and snippets.

@hehongwei44
Last active August 29, 2015 14:03
Show Gist options
  • Save hehongwei44/b5623dda5b43a6731b55 to your computer and use it in GitHub Desktop.
Save hehongwei44/b5623dda5b43a6731b55 to your computer and use it in GitHub Desktop.
通过把父类的对象实例赋值给子类来实现原型式集成
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>js继承</title>
</head>
<body>
<script type="text/javascript">
function Person(name) {
this.name = name;
}
Person.prototype.getName = function(){
return this.name;
}
function User (name,password){
this.name = name;
this.password = password;
}
User.prototype = new Person();
User.prototype.getPassword = function(){
return this.password;
}
var user = new User("john","123456");
console.log(user.getName());
console.log(user.getPassword());
</script>
</body>
</html>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment