Copy code code as follows:
<script type= "Text/javascript" >
<!--
/*
Two ways to add attributes to a prototype prototype
*/
Way One
var myobj = function () {
This.study = "JavaScript";
}
MyObj.prototype.hobby = function ()
{
This.hobby = "Girl";
}
var newObj = new MyObj ();
for (Var attr in NEWOBJ)
{
document.write (attr + "<br/>");
}
document.write ("==================== <br/>");
Mode two
var superobj = {name: "Xugang"};
var subobj = {age:20};
function Extend (superobj,subobj) {
Get the prototype object of the parent object
Subobj.getsuper = Superobj.prototype;
To give the properties of a parent object to child objects
for (var i in superobj) {
Subobj[i] = Superobj[i];
}
}
Extend (superobj,subobj);
For (var s in subobj)
{
document.write (S + "<br/>"); Traversing the properties of child objects
}
-->
</script>
Run Result:
Hobby
Study
====================
Age
GetSuper
Name