// 矩形(构造器/父类)
function Rectangle (height, width) {
this.height = height;
this.width = width;
}
// 获取面积
Rectangle.prototype.getArea = function () {
return this.height * this.width;
}
// 正方形(将继承矩形)
function Square (size) {
this.height = size
this.width = size
}
// 继承的重中之重语法
Square.prototype = new Rectangle();
// 构造函数
Square.prototype.constructor = Square;
var square = new Square(6);
// 调用继承的矩形类的获取面积函数
console.log(square.getArea()) // 36
es5 温故而知新 简单继承示例
猜你喜欢
转载自www.cnblogs.com/CyLee/p/9859254.html
今日推荐
周排行