ES6中的面向对象class,对新手学习理解大有帮助。
2018-04-07 09:42
363 查看
//ES5的做法:
//function Car(options){
// this.style = options.style;
//}
//
//Car.prototype.owner = function(){
// return "ivan";
//}
//
//
//const car = new Car({style:"cool"});
//
//console.log(car.style);
//console.log(car.owner());
//
//function BMW(options){
// var self = this;
// Car.call(self,options);
// this.color = options.color;
//}
//
//BMW.prototype = Object.create(Car.prototype);
//BMW.prototype.constructor = BMW;
//
//const bmw = new BMW({color: "red", style: "bigger"});
//
//console.log(bmw);
//console.log(bmw.owner());
//ES6的做法
class Car{
constructor({style}){
this.style = style;
}
owner(){
return "ivan";
}
}
//const car = new Car({style : "cool"});
//console.log(car);
//console.log(car.owner());
class BMW extends Car{
constructor(options){
super(options);
this.color = options.color;
}
}
const bmw = new BMW({style:"bigger", color :"red"})
console.log(bmw);
console.log(bmw.owner());
//function Car(options){
// this.style = options.style;
//}
//
//Car.prototype.owner = function(){
// return "ivan";
//}
//
//
//const car = new Car({style:"cool"});
//
//console.log(car.style);
//console.log(car.owner());
//
//function BMW(options){
// var self = this;
// Car.call(self,options);
// this.color = options.color;
//}
//
//BMW.prototype = Object.create(Car.prototype);
//BMW.prototype.constructor = BMW;
//
//const bmw = new BMW({color: "red", style: "bigger"});
//
//console.log(bmw);
//console.log(bmw.owner());
//ES6的做法
class Car{
constructor({style}){
this.style = style;
}
owner(){
return "ivan";
}
}
//const car = new Car({style : "cool"});
//console.log(car);
//console.log(car.owner());
class BMW extends Car{
constructor(options){
super(options);
this.color = options.color;
}
}
const bmw = new BMW({style:"bigger", color :"red"})
console.log(bmw);
console.log(bmw.owner());
相关文章推荐
- 如何理解并学习javascript中的面向对象(OOP)
- JavaScript使用ES6的Class面向对象继承时 this is not defined 解决方法
- 08.06_面向对象(通过JDK的帮助文档学习Math类的随机数功能)
- node.js学习之路(二)之“深入理解面向对象的JavaScript”
- 深入理解ES6学习笔记之块级作用域绑定
- PHP面向对象三大特点学习(充分理解抽象、封装、继承、多态)
- 深入学习Django源码基础1 - 深刻理解Python中的元类(metaclass)
- 8 面向对象(制作帮助文档,通过JDK提供的API学习了Math类,代码块,继承(继承子父成员访问特点,super关键字,方法重写))
- 新手帮助:C#高级编程(第7版)中弱事件模式的例子的理解
- tensorflow学习二:概念知识和一个帮助理解的demo
- 帮助理解java面向对象的一些demo
- 【学习】新手可以这样理解“云服务”
- 近几日学习java+jsp+mysql制作网页遇见的错误解决方法,希望对新手有帮助
- 自制消消乐 使用学习vue.js 和 es6 class语法 就写了一个这个游戏 源码 可以去 github 上下载
- Object-c 学习之面向对象的理解
- 黑马程序员-面向对象的理解以及Objective-C方法和对象分配内存的学习笔记
- 【疯狂Java学习笔记】【理解面向对象】
- 我对编程语言的理解,适应新手一起学习。
- 《鬼谷子》帮助理解面向对象思想
- ES6 学习笔记 Class