This is a fork of the awesome chainify library (https://gist.github.com/gists/1466219).
I made it because I don't like with().
bonus: It's much faster! http://jsperf.com/chaining-mehods
demo here: http://jsfiddle.net/ce25R/3/
This is a fork of the awesome chainify library (https://gist.github.com/gists/1466219).
I made it because I don't like with().
bonus: It's much faster! http://jsperf.com/chaining-mehods
demo here: http://jsfiddle.net/ce25R/3/
//chainify | |
function(b,a){for(a in b=b.prototype)(function(c,d){b[a]=function(){d=c.apply(this,arguments);return d==undefined?this:d}})(b[a])} | |
//propertize | |
function(d){d.prototype.prop=function(a,c,b){if(void 0!==c)this[a]=c;else for(b in a)this[b]=a[b];return this}} |
<script> | |
(function(b,a){for(a in b=b.prototype)(function(c,d){b[a]=function(){d=c.apply(this,arguments);return d==undefined?this:d}})(b[a])})(Element); | |
(function(d){d.prototype.prop=function(a,c,b){if(void 0!==c)this[a]=c;else for(b in a)this[b]=a[b];return this}})(Element); | |
document.body.appendChild( | |
document.createElement('a') | |
.prop({ | |
'href': 'http://140byt.es/', | |
'title': 'tiny awsm' | |
}) | |
.prop('innerHTML', '140byt.es') | |
.setAttribute('data-monkeys', '∞') | |
.addEventListener('click', function(){ alert('Urk! Alert!')}, false) | |
); | |
</script> |