From 12c0a1ce72a8c3bfe6fdc25dc1abed103861afcc Mon Sep 17 00:00:00 2001 From: Brian Zengel Date: Fri, 18 Oct 2013 22:23:03 -0400 Subject: [PATCH] added _.bindAll definitions --- lodash/lodash-tests.ts | 24 ++++--- lodash/lodash.d.ts | 151 ++++++++++++++++++++--------------------- 2 files changed, 91 insertions(+), 84 deletions(-) diff --git a/lodash/lodash-tests.ts b/lodash/lodash-tests.ts index ea86b4f0f..c89dbb554 100644 --- a/lodash/lodash-tests.ts +++ b/lodash/lodash-tests.ts @@ -1,6 +1,6 @@ /// -declare var $; +declare var $, jQuery; interface IFoodOrganic { name: string; @@ -399,6 +399,14 @@ var func = function (greeting) { return greeting + ' ' + this.name }; var func2 = _.bind(func, { 'name': 'moe' }, 'hi'); func2(); +var view = { + 'label': 'docs', + 'onClick': function() { console.log('clicked ' + this.label); } +}; + +_.bindAll(view); +jQuery('#docs').on('click', view.onClick); + @@ -421,13 +429,13 @@ func2(); -var buttonView = { - label: 'underscore', - onClick: function () { alert('clicked: ' + this.label); }, - onHover: function () { console.log('hovering: ' + this.label); } -}; -_.bindAll(buttonView); -$('#underscore_button').bind('click', buttonView.onClick); +// var buttonView = { +// label: 'underscore', +// onClick: function () { alert('clicked: ' + this.label); }, +// onHover: function () { console.log('hovering: ' + this.label); } +// }; +// _.bindAll(buttonView); +// $('#underscore_button').bind('click', buttonView.onClick); var fibonacci = _.memoize(function (n) { return n < 2 ? n : fibonacci(n - 1) + fibonacci(n - 2); diff --git a/lodash/lodash.d.ts b/lodash/lodash.d.ts index 8f8fc694d..26e6a56c3 100644 --- a/lodash/lodash.d.ts +++ b/lodash/lodash.d.ts @@ -1719,88 +1719,87 @@ declare module _ { thisArg: any, ...args: any[]): () => any; - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - /** - * Binds a number of methods on the object, specified by methodNames, to be run in the context of that object - * whenever they are invoked. Very handy for binding functions that are going to be used as event handlers, - * which would otherwise be invoked with a fairly useless this. If no methodNames are provided, all of the - * object's function properties will be bound to it. - * @param object The object to bind the methods `methodName` to. - * @param methodNames The methods to bind to `object`, optional and if not provided all of `object`'s - * methods are bound. + * Binds methods of an object to the object itself, overwriting the existing method. Method + * names may be specified as individual arguments or as arrays of method names. If no method + * names are provided all the function properties of object will be bound. + * @param object The object to bind and assign the bound methods to. + * @param methodNames The object method names to bind, specified as individual method names + * or arrays of method names. **/ export function bindAll( object: any, ...methodNames: string[]): any; + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + /** * Partially apply a function by filling in any number of its arguments, without changing its dynamic this value. * A close cousin of bind.