prototype exercise

<html>
<head>
</head>
<body>
<div style="float:left;">
    <div id="div1" style="100px;height:100px;background-color:white;">
    </div>
    <div id="div2" style="100px;height:100px;background-color:white;">
    </div>
</div>
<div id="div3" style="100px;height:200px;background-color:white;float:left;">
</div>
<div id="div4" style="100px;height:200px;background-color:white;float:left;">
</div>
</body>
<script type="text/javascript">
/*function Person(name,age,job){
    this.name = name;
    this.age = age;
    this.job = job;
}
function Man(height,weight){
    this.height = height;
    this.weight = weight;
    this.name = 'aaa';
    Person.call(this,'Jean',100,'dev');
}
var m = new Man(100,100);*/
function object(o){
    function F(){};
    F.prototype = o;
    return new F();
}
function inheritPrototype(subType, superType){
    var p = object(superType.prototype);
    p.constructor = subType;
    subType.prototype = p;
}
function SuperType(name){
    this.name=name;
    this.colors = ["red","blue","green"];
    this.sayColor = function (){
        alert(this.colors);
    };
}
SuperType.prototype.sayName = function(){
    alert(this.name);
};
inheritPrototype(SubType, SuperType);

function SubType(name,age){
    SuperType.call(this,name);
    this.age = age;
}

//SubType.prototype = new SuperType("Ge");

SubType.prototype.sayAge = function(){
    alert(this.age);
};
var i1 = new SubType("Jean",24);
</script>
</html>
原文地址:https://www.cnblogs.com/JingG/p/3090692.html