vue-draggle源码中的策略模式和柯里化
const optionsAdded = {};
eventsListened.forEach(elt => { optionsAdded["on" + elt] = delegateAndEmit.call(this, elt); });
const eventsListened = ["Start", "Add", "Remove", "Update", "End"];
function delegateAndEmit(evtName) { return evtData => { if (this.realList !== null) { this["onDrag" + evtName](evtData); } emit.call(this, evtName, evtData); }; }
function emit(evtName, evtData) { this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData)); }
2.另一个方法的策略
const optionsAdded = {};
eventsToEmit.forEach(elt => { optionsAdded["on" + elt] = emit.bind(this, elt); });
const eventsToEmit = ["Choose", "Unchoose", "Sort", "Filter", "Clone"];
function emit(evtName, evtData) { this.$nextTick(() => this.$emit(evtName.toLowerCase(), evtData)); }