Skip to content

Instantly share code, notes, and snippets.

@chrisslater
Last active August 29, 2015 14:01
Show Gist options
  • Save chrisslater/538101460e722697bfe9 to your computer and use it in GitHub Desktop.
Save chrisslater/538101460e722697bfe9 to your computer and use it in GitHub Desktop.
Cached 'Functional' patterned mixin, using curry to invoke config parameters.
/* ==========================================================================
Cached 'Functional' patterned mixin, using curry to invoke config parameters.
===========================================================================*/
// Create curry prototype;
Function.prototype.curry = function(){
var slice = Array.prototype.slice,
args = slice.apply(arguments),
that = this;
return function(){
return that.apply(this, args.concat(
slice.apply(slice.apply(arguments))
));
};
};
// Create the DragableMixin and cache it
var DraggableMixin = (function(){
var startDrag = function(config, options){};
var onDrag = function(){};
return function(config){
this.startDrag = startDrag.curry(config);
this.onDrag = onDrag;
return this;
};
})();
var UserItemView = function(){};
DraggableMixin.call(UserItemView.prototype, {foo: 'bar'});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment