Simplify _.bindAll.

Former-commit-id: 02de2a2a6020461d42e222a476c2fb7e66f6895e
This commit is contained in:
John-David Dalton
2012-10-19 08:16:11 -07:00
parent e1643566f9
commit ada6115073
4 changed files with 45 additions and 40 deletions

View File

@@ -427,7 +427,7 @@
'inLoop': 'if (callback(value, index, collection) === false) return result'
};
/** Reusable iterator options for `bindAll`, `defaults`, and `extend` */
/** Reusable iterator options for `defaults`, and `extend` */
var extendIteratorOptions = {
'useHas': false,
'useStrict': false,
@@ -662,6 +662,9 @@
if ((data.firstArg = /^[^,]+/.exec(args)[0]) != 'collection' || !data.arrayBranch.inLoop) {
data.arrayBranch = null;
}
if (!data.objectBranch.inLoop) {
data.objectBranch = null;
}
// create the function factory
var factory = Function(
'bind, createCallback, forIn, hasOwnProperty, isArguments, isFunction, ' +
@@ -3204,7 +3207,9 @@
* jQuery('#lodash_button').on('click', buttonView.onClick);
* // => When the button is clicked, `this.label` will have the correct value
*/
var bindAll = createIterator(extendIteratorOptions, {
var bindAll = createIterator({
'useStrict': false,
'args': 'object',
'top':
'var funcs = arguments,\n' +
' length = funcs.length;\n' +
@@ -3214,10 +3219,10 @@
' result[index] = bind(result[index], result)\n' +
' }\n' +
' return result\n' +
'}',
'inLoop':
'if (isFunction(value)) result[index] = bind(value, result)',
'bottom': false
'}\n' +
'forIn(result, function(value, key) {\n' +
' if (isFunction(value)) result[key] = bind(value, result)\n' +
'})'
});
/**