added _.createCallback definition, added forgotten return type castings in tests

This commit is contained in:
Brian Zengel
2013-10-18 23:00:43 -04:00
parent 9ffae95370
commit 2fabed36e4
2 changed files with 30 additions and 7 deletions
+8 -6
View File
@@ -385,7 +385,7 @@ result = <IStoogesCombined[]>_.where(stoogesCombined, { 'quotes': ['Poifect!'] }
var saves = ['profile', 'settings'];
var asyncSave = (obj) => obj.done();
var done = _.after(saves.length, function() {
var done: Function = _.after(saves.length, function() {
console.log('Done saving!');
});
@@ -396,7 +396,7 @@ _.forEach(saves, function(type) {
var funcBind = function (greeting) { return greeting + ' ' + this.name };
// need a second var otherwise typescript thinks func signature is the above func type,
// instead of the newly returned _bind => func type.
var funcBind2 = _.bind(funcBind, { 'name': 'moe' }, 'hi');
var funcBind2: () => any = _.bind(funcBind, { 'name': 'moe' }, 'hi');
funcBind2();
var view = {
@@ -404,7 +404,7 @@ var view = {
'onClick': function() { console.log('clicked ' + this.label); }
};
_.bindAll(view);
view = _.bindAll(view);
jQuery('#docs').on('click', view.onClick);
var objectBindKey = {
@@ -414,7 +414,7 @@ var objectBindKey = {
}
};
var funcBindKey = _.bindKey(object, 'greet', 'hi');
var funcBindKey: Function = _.bindKey(object, 'greet', 'hi');
funcBindKey();
objectBindKey.greet = function(greeting) {
@@ -436,10 +436,12 @@ var greet = function(formatted) {
return 'Hiya ' + formatted + '!';
};
var welcome = _.compose(greet, format);
var welcome: Function = _.compose(greet, format);
welcome('curly');
var createCallbackObj = { name: 'Joe' };
var pluckCallback: () => any = _.createCallback('name');
var whereCallback: () => boolean = _.createCallback(createCallbackObj);
////////////////////////////////////////////////////////////////////////////////////////
+22 -1
View File
@@ -1726,6 +1726,7 @@ declare module _ {
* @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.
* @return object
**/
export function bindAll(
object: any,
@@ -1756,8 +1757,28 @@ declare module _ {
**/
export function compose(...funcs: Function[]): Function;
/**
* Produces a callback bound to an optional thisArg. If func is a property name the created
* callback will return the property value for a given element. If func is an object the created
* callback will return true for elements that contain the equivalent object properties,
* otherwise it will return false.
* @param func The value to convert to a callback.
* @param thisArg The this binding of the created callback.
* @param argCount The number of arguments the callback accepts.
* @return A callback function.
**/
export function createCallback(
func: string,
thisArg?: any,
argCount?: number): () => any;
/**
* @see _.createCallback
**/
export function createCallback(
func: Dictionary<any>,
thisArg?: any,
argCount?: number): () => boolean;