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
    
  • 相关阅读:
    harbor两层nginx代理导致push不成功401
    docker hub国内镜像
    iOS越狱后导入照片
    Failed to list *v1.Secret: secrets is forbidden: User "system:node
    Centos设置limit最大打开文件数和最大进程数
    grafana设置主页面板
    MySQL数据库设计规范
    tcp time_wait
    mysqldiff No module named utilities.common.tools
    mongodb 慢查询排查
  • 原文地址:https://www.cnblogs.com/CyLee/p/9859254.html
Copyright © 2011-2022 走看看