Skip to content

Instantly share code, notes, and snippets.

@ezekielchentnik
Created December 2, 2014 23:42
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save ezekielchentnik/bd19b600396e91c0807f to your computer and use it in GitHub Desktop.
Save ezekielchentnik/bd19b600396e91c0807f to your computer and use it in GitHub Desktop.
function attrify(config) {
var properties = {};
for (var prop in config) {
if (prop && config.hasOwnProperty(prop)) {
properties[prop] = (function(name) {
return function() {
if (!arguments.length) {
return config[name];
}
config[name] = arguments[0];
return properties;
};
}(prop));
}
}
return properties;
}
var x = attrify({
width: 100,
height: 200
});
x.size = function() {
console.log(this.width(), this.height());
};
x.size();
x.width(300).height(400);
console.log(x.width(), x.height());
x.size();
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment