Created
April 25, 2014 19:16
-
-
Save subtubes-io/11300061 to your computer and use it in GitHub Desktop.
Basic JavaScript mixin paattern
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
(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