Use a Mixin to Add Common Behavior Between Unrelated Objects

Use a Mixin to Add Common Behavior Between Unrelated Objects
0.0 0

#1

Tell us what’s happening:

Your code so far


let bird = {
  name: "Donald",
  numLegs: 2
};

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

// Add your code below this line

let glideMixin = function(glide) {
  glideMixin.bird = function(glide) {
    console.log("glide");
  }
}




Your browser information:

User Agent is: Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/66.0.3359.181 Safari/537.36.

Link to the challenge:
https://learn.freecodecamp.org/javascript-algorithms-and-data-structures/object-oriented-programming/use-a-mixin-to-add-common-behavior-between-unrelated-objects


#2

Mh, the function is a bit messy; the parameter of the first function indicate the ‘object’ you want to give the ability to glide: I suggest you to give it a more general name to not being confused.
Inside the first function you should define the method ( in the challenge is ‘glide’, i’m using something else for example purpose ) applied to the object you passed in through the first function: something like

let firstFunc = function(stuff) {
  stuff.turn = function () {
         "I am turning, whoo!!"
       }
}

After that, you’re missing the part where you assign different objects the ability to glide, something like:

firstFunc(me);
firstFunc(you);
firstFunc(anyoneElse);
..

Hope it helps!


#3

You should use like this

let glideMixin = function(boat) {
 boat.glide = function() {
     console.log("anythio");
 }
}
glideMixin(bird);
glideMixin(boat);