javascript原型链测试

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">

<html xmlns="http://www.w3.org/1999/xhtml">

<head>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

<title>原型链测试</title>

</head>

<div id="divtest" ></div>

<body>

</body>

<script language="javascript" type="application/javascript"  src="../js/mutiprototype.js"></script>

</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的属性与方法;

你可能感兴趣的:(javascript原型链测试)