1.为什么在子类的constructor里面要加一句super()? 答:如果子类用了extends的关键字继承的父类,那么子类在使用构造器的时候就要加super()语句,这是语法规范,就是这么定的. 2.super()究竟是什么? 是父类中的一个方法, 3.为什么加了super之后,显示的数据就成了undefined? 没有把值传过去,只要加上就可以了,super(name,age) class Chinese extends Person{ constructor {super()} } c
https://developer.mozilla.org/zh-CN/docs/Web/JavaScript/Reference/Operators/super The super keyword is used to access and call functions on an object's parent. super关键字用于访问和调用一个对象的父对象上的函数. The super.prop and super[expr] expressions are valid in any m
ECMAScript 5 中引入了一个新方法:Object.create().可以调用这个方法来创建一个新对象.新对象的原型就是调用 create 方法时传入的第一个参数: var a = {a: 1}; // a ---> Object.prototype ---> null var b = Object.create(a); // b ---> a ---> Object.prototype ---> null console.log(b.a); // 1 (继承而来)
14down votefavorite An article on classloading states that the method getClass() should not be called within a constructor because: object initialization will be complete only at the exit of the constructor code. The example they gave was: public c
大家都知道this 和 super 调用构造函数时都必须放在第一句,今天同学问我的一个问题有点意思. 那么:我怎么在子类中 显式的用 super 初始化父类同时用 this 初始化子类? ------------------------------------------------------------------------------------- 首先大家必须认识到两点: 1. super 调用构造函数的 作用是 为了初始化子类前先初始化父类,仅此而已. 2. 每个类的构造函数有且仅有