Created
December 2, 2014 23:42
-
-
Save ezekielchentnik/bd19b600396e91c0807f 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 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