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
    
  • 相关阅读:
    二叉树的深度(剑指offer)
    平衡二叉树(剑指offer)
    平衡二叉树
    513. Find Bottom Left Tree Value(得到左下角的节点)(树的层次遍历)
    637. Average of Levels in Binary Tree(一棵树每层节点的平均数)(二叉树的层序遍历)
    145. Binary Tree Postorder Traversal(非递归实现二叉树的后序遍历)
    正则表达式式总结
    re模块
    生成器 生成器函数 列表推倒式 生成器表达式
    闭包,迭代器
  • 原文地址:https://www.cnblogs.com/CyLee/p/9859254.html
Copyright © 2011-2022 走看看