SoFunction
Updated on 2025-02-28

Two ways to add attributes to object prototype prototype


<script type="text/javascript">
<!--
/*
Two ways to add attributes to prototype prototype
*/
//Method One
var myObj = function(){
= "JavaScript";
}
= function()
{
= "See girl";
}
var newObj = new myObj();
for ( var attr in newObj )
{
( attr +"<br/>" );
}
( "==================== <br/>" );
//Method 2
var superObj = { name:"xugang" };
var subObj = { age:20 };
function extend(superObj,subObj){
//Get the parent object's prototype object
= ;
//Give the parent object's attributes to the child object
for(var i in superObj){
subObj[i] = superObj[i];
}
}
extend(superObj,subObj);
for ( var s in subObj )
{
( s +"<br/>" ); //Transfer the properties of the sub-object
}
//-->
</script>