Last active
August 29, 2015 14:01
-
-
Save chrisslater/538101460e722697bfe9 to your computer and use it in GitHub Desktop.
Cached 'Functional' patterned mixin, using curry to invoke config parameters.
This file contains hidden or 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
/* ========================================================================== | |
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