<! DOCTYPE html>
<meta charset= "UTF-8" >
<title></title>
<script type= "Text/javascript" >
(function () {
var Shape = new Object ();
Shape.color = "#O8c671";
Shape.area = "50px";
document.write ("Shape's color:" + Shape.color + "," + "shape's area is:" + Shape.area + "Parent object <br/>");
function Circle () {
document.write ("Circle color:" + This.color + "," + "Circle area is:" + This.area + "sub-object <br/>")
}
Circle.call (Shape);
function Rect () {
document.write ("Rect color:" + This.color + "," + "rect area is:" + This.area + "sub-object <br/>")
}
Rect.call (Shape);
})();
</script>
<body>
</body>
This case defines shape as the parent object, Circle and rect as child objects, and an inheritance relationship, and after inheriting two subclasses have the parent property color and area, line 19th calls the call method, the This reference is specified as shape, So the this.color in the function circle is equal to Shape.color. So we have the parent attribute, and the following rect is similar
Shape's color: #O8c671, Shape's area is: 50px Parent object
Color of Circle: #O8c671, the area of Circle is: 50px Sub-object
Color of rect: #O8c671, the area of rect is: 50px Sub-object
This case defines shape as the parent object, Circle and rect as child objects, and an inheritance relationship, and after inheriting two subclasses have the parent property color and area, line 19th calls the call method, the This reference is specified as shape, So the this.color in the function circle is equal to Shape.color. So we have the parent attribute, and the following rect is similar
JavaScript inheritance, call ()