freeCodeCamp Challenge Guide: Use a Mixin to Add Common Behavior Between Unrelated Objects

Use a Mixin to Add Common Behavior Between Unrelated Objects


Problem Explanation

Just like the flyMixin function, a new glideMixin function must be made to accept both bird and boat objects as a parameter. Create this new function using the same syntax as the flyMixin function and then call the function on both objects.


Solutions

Solution 1 (Click to Show/Hide)
let bird = {
  name: "Donald",
  numLegs: 2
};

let boat = {
  name: "Warrior",
  type: "race-boat"
};

// Add your code below this line
let glideMixin = function(obj) {
  obj.glide = function() {
    console.log("Gliding!");
  };
};
glideMixin(bird);
glideMixin(boat);
2 Likes