Java Reference
In-Depth Information
We can use this idea to add super powers to our superhero objects used earlier. All the su-
perheroes are superhuman, so they inherited any common traits from a Superhuman pro-
totype object. But they also have super-powers, and each superhero has a different mix of
powers. This is a perfect use case for mixin objects: we can create some super-power mixin
objects that can then be added to any of our super hero objects as required:
flight = {
fly: function() {
console.log(Up, up and away! " + + " soars
through the
return this;
superSpeed = {
move: function() {
console.log( + " can move faster than a
return this;
xRayVision = {
xray: function() {
console.log( + " can see right through you!");
return this;
Now the relevant super powers can be added in a modular fashion to each of the super hero
objects using the mixin() method:
Search WWH ::

Custom Search