zoukankan      html  css  js  c++  java
  • es5 温故而知新 简单继承示例

    // 矩形(构造器/父类)
    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 = Object.create(Rectangle.prototype)
    Square.prototype = Object.create(Rectangle.prototype);
    // 构造函数
    Square.prototype.constructor = Square;
    
    var square = new Square(6);
    // 调用继承的矩形类的获取面积函数
    console.log(square.getArea()) // 36
    
  • 相关阅读:
    sql练手
    简单工厂模式和抽象工厂模式的区别:面向接口编程
    UML中聚合和组合的关系(笔记)
    如何修改SQL Server 2005服务器名称 (装载)
    .NET 图片处理剪裁
    sql server 中的汉字转化为拼音
    sql server while, case,if..else ... try catch ..对象
    String 和 StringBuilder 的相同点和不同点
    sql 折分字符串并修改数据库表中数据
    SQL Server 与 Excel,Access 数据表的导入导出(注:参照博园.NET大观)
  • 原文地址:https://www.cnblogs.com/CyLee/p/9859254.html
Copyright © 2011-2022 走看看