Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- let running = {
- getDetails() {
- console.log(`Heading towards ${this.direction} at ${this.speed}`);
- }
- }
- let Airplane = function(speed, direction){
- this.speed = speed;
- this.direction = direction;
- }
- let boeing787 = new Airplane('400 mph', 'North');
- boeing787 = Object.assign(boeing787, running);
- console.log(boeing787.getDetails()); //Heading towards North at 400mph
- //Mixins in ES6 Class
- let runningStatus = {
- setRunnigStatus(speed, direction) {
- this.speed = speed;
- this.direction = direction;
- },
- getRunnigStatus(){
- console.log(`Flying at ${this.speed} towards ${this.direction}`);
- }
- }
- class Airplane {
- constructor(name) {
- this.name = name;
- }
- }
- Object.assign(Airplane.prototype, runningStatus);
- let airplane = new Airplane("Boeing 787");
- airplane.setRunnigStatus("490 mph", "South East");
- airplane.getRunnigStatus(); // Flying at 490 mph towards South East
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement