Revert "Create #alias method, callable on any object, _ by default."

This reverts commit c43de549ba.

Conflicts:

	test/objects.js
This commit is contained in:
Mike Frawley
2010-02-23 17:26:32 -06:00
parent 164e19c121
commit 59d383c151
2 changed files with 11 additions and 51 deletions

View File

@@ -11,7 +11,7 @@ $(document).ready(function() {
}); });
test("objects: functions", function() { test("objects: functions", function() {
var expected = ["alias", "all", "any", "bind", "bindAll", "breakLoop", "buildLookup", "clone", "compact", var expected = ["all", "any", "bind", "bindAll", "breakLoop", "buildLookup", "clone", "compact",
"compose","defer", "delay", "detect", "each", "every", "extend", "filter", "first", "compose","defer", "delay", "detect", "each", "every", "extend", "filter", "first",
"flatten", "foldl", "foldr", "forEach", "functions", "head", "identity", "include", "flatten", "foldl", "foldr", "forEach", "functions", "head", "identity", "include",
"indexOf", "inject", "intersect", "invoke", "isArguments", "isArray", "isDate", "isElement", "isEmpty", "isEqual", "indexOf", "inject", "intersect", "invoke", "isArguments", "isArray", "isDate", "isElement", "isEmpty", "isEqual",
@@ -19,7 +19,7 @@ $(document).ready(function() {
"methods", "min", "noConflict", "pluck", "range", "reduce", "reduceRight", "reject", "rest", "select", "methods", "min", "noConflict", "pluck", "range", "reduce", "reduceRight", "reject", "rest", "select",
"size", "some", "sortBy", "sortedIndex", "tail", "tap", "template", "times", "toArray", "uniq", "size", "some", "sortBy", "sortedIndex", "tail", "tap", "template", "times", "toArray", "uniq",
"uniqueId", "values", "without", "wrap", "zip"]; "uniqueId", "values", "without", "wrap", "zip"];
ok(_(expected).isEqual(_.methods(_)), 'provides a sorted list of functions'); same(expected, _.methods(_), 'provides a sorted list of functions');
var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce}; var obj = {a : 'dash', b : _.map, c : (/yo/), d : _.reduce};
ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object'); ok(_.isEqual(['b', 'd'], _.functions(obj)), 'can grab the function names of any passed-in object');
}); });
@@ -185,19 +185,4 @@ $(document).ready(function() {
value(); value();
ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain'); ok(returned == 6 && intercepted == 6, 'can use tapped objects in a chain');
}); });
test("objects: alias", function() {
_.alias('isEqual', 'isTheSame');
ok(_.isTheSame(9, 9), 'by default aliases methods on underscore');
delete _.isTheSame;
//
var o = { hi: function () {return 9;} };
_.alias(o, 'hi', 'ho');
equals(o.ho(), 9, 'can add an alias on another object');
_.alias(o, 'hi', 'there', 'sir');
ok(o.hi==o.sir, 'can add multiple aliases');
});
}); });

View File

@@ -470,31 +470,6 @@
return obj; return obj;
}; };
// Alias a method on an object to another name(s).
// If the first argument is NOT an object, then the object is assumed to
// be underscore.
// The first string argument is the existing method name, any following
// strings will be aliased to that name.
// Returns the object for chainability.
//
// Examples:
//
// Alias isEquals to isSame and eql on underscore:
// _.alias('isEqual', 'isSame', 'eql');
//
// Alias `toString` to `to_s` on a given object:
// _.alias({}, 'toString', 'to_s')
//
// Implementation: explicitly cast arguments to array as calling mutating
// array methods on arguments object has strange behavior (at least in FF 3.6)
_.alias = function () {
var args = _.toArray(arguments),
obj = (typeof args[0] === 'string')? _ : args.shift(),
fn = obj[args.shift()];
each(args, function (alias) { obj[alias] = fn; });
return obj;
};
// Perform a deep comparison to check if two objects are equal. // Perform a deep comparison to check if two objects are equal.
_.isEqual = function(a, b) { _.isEqual = function(a, b) {
// Check object identity. // Check object identity.
@@ -658,15 +633,15 @@
// ------------------------------- Aliases ---------------------------------- // ------------------------------- Aliases ----------------------------------
_.alias('forEach', 'each'). _.each = _.forEach;
alias('reduce', 'foldl', 'inject'). _.foldl = _.inject = _.reduce;
alias('reduceRight', 'foldr'). _.foldr = _.reduceRight;
alias('filter', 'select'). _.select = _.filter;
alias('every', 'all'). _.all = _.every;
alias('some', 'any'). _.any = _.some;
alias('first', 'head'). _.head = _.first;
alias('rest', 'tail'). _.tail = _.rest;
alias('functions', 'methods'); _.methods = _.functions;
// ------------------------ Setup the OOP Wrapper: -------------------------- // ------------------------ Setup the OOP Wrapper: --------------------------