Last active
August 29, 2015 14:23
-
-
Save brandonhesse/1379622b3fb310361f1b to your computer and use it in GitHub Desktop.
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 checkbox = (function checkBoxBuilder() { | |
var prototype = { | |
values: function () { | |
var keys = Object.keys(this); | |
var type = this; | |
return keys.filter(function (key) { | |
return type[key]; | |
}); | |
} | |
}; | |
return function checkbox(obj) { | |
obj = obj || {}; | |
var objDescriptor = {}; | |
Object.getOwnPropertyNames(obj).forEach(function (key) { | |
try { | |
objDescriptor[key] = Object.getOwnPropertyDescriptor(obj, key); | |
} catch (e) { | |
objDescriptor[key] = { | |
value: obj[key], | |
enumerable: true, | |
writable: true, | |
configurable: true | |
}; | |
} | |
}); | |
return Object.create(prototype, objDescriptor); | |
}; | |
}()); | |
var improvements = checkbox({a: true, b: false, c: true, d: false}); | |
console.log(improvements); | |
console.log(improvements.values()); | |
}()); |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment