<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">javascript
<html xmlns="http://www.w3.org/1999/xhtml">html
<head>java
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />瀏覽器
<title>原型鏈測試</title>app
</head>工具
<div id="divtest" ></div>測試
<body>ui
</body>this
<script language="javascript" type="application/javascript" src="../js/mutiprototype.js"></script>spa
</html>
------------js---
// JavaScript Document
function User(name)
{
this.name = name;
}
User.prototype.getName = function()
{
return this.name;
}
function VipUser(name,password)
{
this.name=name;
this.password=password;
}
VipUser.prototype = new User("not zxg");
VipUser.prototype.getPassword=function()
{
return this.password;
}
var vip = new VipUser("zxg","12346");
var divtest = document.getElementById("divtest");
divtest.innerHTML += vip.getName();
divtest.innerHTML += vip.__proto__.getName();
能夠在瀏覽器調試工具中看到vip的屬性與方法;