1
0
Fork 0
mirror of https://github.com/jashkenas/coffeescript.git synced 2022-11-09 12:23:24 -05:00

more underscore and bugfix edits to code generation

This commit is contained in:
Jeremy Ashkenas 2009-12-26 22:24:21 -08:00
parent d7dd18b476
commit 3ee4e98ccc
2 changed files with 38 additions and 46 deletions

View file

@ -113,52 +113,43 @@ _.reduceRight: obj, memo, iterator, context =>
_.breakLoop() unless result: result and iterator.call(context, value, index, list).)) _.breakLoop() unless result: result and iterator.call(context, value, index, list).))
result. result.
# # Determine if at least one element in the object matches a truth test. Use # Determine if at least one element in the object matches a truth test. Use
# # JavaScript 1.6's some(), if it exists. # JavaScript 1.6's some(), if it exists.
# _.any = function(obj, iterator, context) { _.any: obj, iterator, context =>
# iterator = iterator || _.identity; iterator ||= _.identity
# if (obj && _.isFunction(obj.some)) return obj.some(iterator, context); return obj.some(iterator, context) if obj and _.isFunction(obj.some)
# var result = false; result: false
# _.each(obj, function(value, index, list) { _.each(obj, (value, index, list =>
# if (result = iterator.call(context, value, index, list)) _.breakLoop(); _.breakLoop() if (result: iterator.call(context, value, index, list)).))
# }); result.
# return result;
# }; # Determine if a given value is included in the array or object,
# # based on '==='.
# # Determine if a given value is included in the array or object, _.include: obj, target =>
# # based on '==='. return _.indexOf(obj, target) isnt -1 if _.isArray(obj)
# _.include = function(obj, target) { found: false
# if (_.isArray(obj)) return _.indexOf(obj, target) != -1; _.each(obj, (value =>
# var found = false; _.breakLoop() if (found: value is target).))
# _.each(obj, function(value) { found.
# if (found = value === target) _.breakLoop();
# }); # Invoke a method with arguments on every item in a collection.
# return found; _.invoke: obj, method =>
# }; args: _.rest(arguments, 2)
# _.map(obj, (value =>
# # Invoke a method with arguments on every item in a collection. (if method then value[method] else value.).apply(value, args).)).
# _.invoke = function(obj, method) {
# var args = _.rest(arguments, 2); # Convenience version of a common use case of map: fetching a property.
# return _.map(obj, function(value) { _.pluck: obj, key =>
# return (method ? value[method] : value).apply(value, args); _.map(obj, (value => value[key].)).
# });
# }; # Return the maximum item or (item-based computation).
# _.max: obj, iterator, context =>
# # Convenience version of a common use case of map: fetching a property. return Math.max.apply(Math, obj) if !iterator and _.isArray(obj)
# _.pluck = function(obj, key) { result: {computed: -Infinity}
# return _.map(obj, function(value){ return value[key]; }); _.each(obj, (value, index, list =>
# }; computed: if iterator then iterator.call(context, value, index, list) else value.
# computed >= result.computed and (result: {value: value, computed: computed}).))
# # Return the maximum item or (item-based computation). result.value.
# _.max = function(obj, iterator, context) {
# if (!iterator && _.isArray(obj)) return Math.max.apply(Math, obj);
# var result = {computed : -Infinity};
# _.each(obj, function(value, index, list) {
# var computed = iterator ? iterator.call(context, value, index, list) : value;
# computed >= result.computed && (result = {value : value, computed : computed});
# });
# return result.value;
# };
# #
# # Return the minimum element (or element-based computation). # # Return the minimum element (or element-based computation).
# _.min = function(obj, iterator, context) { # _.min = function(obj, iterator, context) {

View file

@ -95,6 +95,7 @@ module CoffeeScript
if node.statement? || node.custom_return? if node.statement? || node.custom_return?
"#{o[:indent]}#{node.compile(o)}#{node.line_ending}" "#{o[:indent]}#{node.compile(o)}#{node.line_ending}"
else else
o.delete(:return)
"#{o[:indent]}return #{node.compile(o)}#{node.line_ending}" "#{o[:indent]}return #{node.compile(o)}#{node.line_ending}"
end end
elsif o[:assign] elsif o[:assign]