ES6-extends
来源:互联网 发布:安卓看图软件 编辑:程序博客网 时间:2024/06/05 09:18
extends继承,ColorPoint 子类,Point 父类
1.super关键字,它在这里表示父类的构造函数,用来新建父类的this对象。
3.super这个关键字,既可以当作函数使用,也可以当作对象使用。在这两种情况下,它的用法完全不同
1.super关键字,它在这里表示父类的构造函数,用来新建父类的this对象。
3.super这个关键字,既可以当作函数使用,也可以当作对象使用。在这两种情况下,它的用法完全不同
4.第一种情况,super作为函数调用时,代表父类的构造函数
5.super作为对象时,指向父类的原型对象。
class Point{ constructor(x, y) { this.x = x; this.y = y; } } Object.assign(Point.prototype, { toString(){ return this.x+this.y; }, toValue(){} });class ColorPoint extends Point { constructor(x, y, color) { super(x, y); // 调用父类的constructor(x, y), this.color = color; } toString() { return this.color + ' ' + super.toString(); // 调用父类的toString() }}let cPoint = new ColorPoint(3,3,"red");console.log(cPoint);
class A { constructor(x){ this.x = 1; }; p() { return 2; }}class B extends A { constructor(x) { super(); this.x = 2; super.x = 3; console.log(this.x); // 2 console.log(super.x); // undefined console.log(A.prototype.x); // super.x赋值为3,这时等同于对this.x赋值为3。而当读取super.x的时候,读的是A.prototype.x,所以返回undefined。 }}let b = new B();let a = new A();console.log(a.x);
阅读全文
0 0
- ES6-extends
- es6中类和extends的本质
- 从ES6中的extends讲js原型链与继承
- extends
- extends
- Extends
- Extends
- ES6 类(Class)的继承(extends)和自定义存(setter)取值(getter)详解
- ES6---通过class构造函数extends、public在其中的作用
- ES6学习记录之class, extends, super和箭头函数与this
- es6
- es6
- ES6
- ES6
- ES6
- es6
- ES6
- ES6
- autocomplete+PHP+MYSQL的实现模糊查询
- 解决手机网页内容层随着遮罩层滚动问题
- 微信公众平台开发(97) 图文消息
- 微信公众平台开发接口PHP SDK完整版
- 美团推荐系统
- ES6-extends
- mobiscroll 插件札记(一)
- 踏上程序员之路,事与愿违—却—乐此不彼
- js 上传图片预览
- Jquery实现异步上传图片
- 计算机网络中的七层模型
- jQuery插件之ajaxFileUpload
- ajaxFileUpload 报这错jQuery.handleError is not a function
- 监听上传文件进度条