Skip to content

Instantly share code, notes, and snippets.

@subtubes-io
Created April 25, 2014 19:16
Show Gist options
  • Save subtubes-io/11300061 to your computer and use it in GitHub Desktop.
Save subtubes-io/11300061 to your computer and use it in GitHub Desktop.
Basic JavaScript mixin paattern
(function () {
"use strict";
var mixin = function () {
var arg,
prop,
mixedChild = { },
len = arguments.length;
for (arg = 0; arg < len; arg ++) {
for (prop in arguments[arg]) {
if (arguments[arg].hasOwnProperty(prop)) {
mixedChild[prop] = arguments[arg][prop];
}
}
}
return mixedChild;
};
var wheels = {wheels: 4, offRoad: true},
seats = {seats: 2, bucket: true} ,
doors = {doors: 2, suicide: false},
fuel = {mpg: 6, diesel: false};
var duneBuggy = mixin(wheels, seats, doors, fuel);
console.log(duneBuggy);
}());
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment