Edit File by line
/home/barbar84/www/wp-conte.../plugins/wp-file-.../lib/codemirr.../mode/coffeesc...
File: index.html
<!doctype html>
[0] Fix | Delete
[1] Fix | Delete
<title>CodeMirror: CoffeeScript mode</title>
[2] Fix | Delete
<meta charset="utf-8"/>
[3] Fix | Delete
<link rel=stylesheet href="../../doc/docs.css">
[4] Fix | Delete
[5] Fix | Delete
<link rel="stylesheet" href="../../lib/codemirror.css">
[6] Fix | Delete
<script src="../../lib/codemirror.js"></script>
[7] Fix | Delete
<script src="coffeescript.js"></script>
[8] Fix | Delete
<style>.CodeMirror {border-top: 1px solid silver; border-bottom: 1px solid silver;}</style>
[9] Fix | Delete
<div id=nav>
[10] Fix | Delete
<a href="http://codemirror.net"><h1>CodeMirror</h1><img id=logo src="../../doc/logo.png"></a>
[11] Fix | Delete
[12] Fix | Delete
<ul>
[13] Fix | Delete
<li><a href="../../index.html">Home</a>
[14] Fix | Delete
<li><a href="../../doc/manual.html">Manual</a>
[15] Fix | Delete
<li><a href="https://github.com/codemirror/codemirror">Code</a>
[16] Fix | Delete
</ul>
[17] Fix | Delete
<ul>
[18] Fix | Delete
<li><a href="../index.html">Language modes</a>
[19] Fix | Delete
<li><a class=active href="#">CoffeeScript</a>
[20] Fix | Delete
</ul>
[21] Fix | Delete
</div>
[22] Fix | Delete
[23] Fix | Delete
<article>
[24] Fix | Delete
<h2>CoffeeScript mode</h2>
[25] Fix | Delete
<form><textarea id="code" name="code">
[26] Fix | Delete
# CoffeeScript mode for CodeMirror
[27] Fix | Delete
# Copyright (c) 2011 Jeff Pickhardt, released under
[28] Fix | Delete
# the MIT License.
[29] Fix | Delete
#
[30] Fix | Delete
# Modified from the Python CodeMirror mode, which also is
[31] Fix | Delete
# under the MIT License Copyright (c) 2010 Timothy Farrell.
[32] Fix | Delete
#
[33] Fix | Delete
# The following script, Underscore.coffee, is used to
[34] Fix | Delete
# demonstrate CoffeeScript mode for CodeMirror.
[35] Fix | Delete
#
[36] Fix | Delete
# To download CoffeeScript mode for CodeMirror, go to:
[37] Fix | Delete
# https://github.com/pickhardt/coffeescript-codemirror-mode
[38] Fix | Delete
[39] Fix | Delete
# **Underscore.coffee
[40] Fix | Delete
# (c) 2011 Jeremy Ashkenas, DocumentCloud Inc.**
[41] Fix | Delete
# Underscore is freely distributable under the terms of the
[42] Fix | Delete
# [MIT license](http://en.wikipedia.org/wiki/MIT_License).
[43] Fix | Delete
# Portions of Underscore are inspired by or borrowed from
[44] Fix | Delete
# [Prototype.js](http://prototypejs.org/api), Oliver Steele's
[45] Fix | Delete
# [Functional](http://osteele.com), and John Resig's
[46] Fix | Delete
# [Micro-Templating](http://ejohn.org).
[47] Fix | Delete
# For all details and documentation:
[48] Fix | Delete
# http://documentcloud.github.com/underscore/
[49] Fix | Delete
[50] Fix | Delete
[51] Fix | Delete
# Baseline setup
[52] Fix | Delete
# --------------
[53] Fix | Delete
[54] Fix | Delete
# Establish the root object, `window` in the browser, or `global` on the server.
[55] Fix | Delete
root = this
[56] Fix | Delete
[57] Fix | Delete
[58] Fix | Delete
# Save the previous value of the `_` variable.
[59] Fix | Delete
previousUnderscore = root._
[60] Fix | Delete
[61] Fix | Delete
### Multiline
[62] Fix | Delete
comment
[63] Fix | Delete
###
[64] Fix | Delete
[65] Fix | Delete
# Establish the object that gets thrown to break out of a loop iteration.
[66] Fix | Delete
# `StopIteration` is SOP on Mozilla.
[67] Fix | Delete
breaker = if typeof(StopIteration) is 'undefined' then '__break__' else StopIteration
[68] Fix | Delete
[69] Fix | Delete
[70] Fix | Delete
#### Docco style single line comment (title)
[71] Fix | Delete
[72] Fix | Delete
[73] Fix | Delete
# Helper function to escape **RegExp** contents, because JS doesn't have one.
[74] Fix | Delete
escapeRegExp = (string) -> string.replace(/([.*+?^${}()|[\]\/\\])/g, '\\$1')
[75] Fix | Delete
[76] Fix | Delete
[77] Fix | Delete
# Save bytes in the minified (but not gzipped) version:
[78] Fix | Delete
ArrayProto = Array.prototype
[79] Fix | Delete
ObjProto = Object.prototype
[80] Fix | Delete
[81] Fix | Delete
[82] Fix | Delete
# Create quick reference variables for speed access to core prototypes.
[83] Fix | Delete
slice = ArrayProto.slice
[84] Fix | Delete
unshift = ArrayProto.unshift
[85] Fix | Delete
toString = ObjProto.toString
[86] Fix | Delete
hasOwnProperty = ObjProto.hasOwnProperty
[87] Fix | Delete
propertyIsEnumerable = ObjProto.propertyIsEnumerable
[88] Fix | Delete
[89] Fix | Delete
[90] Fix | Delete
# All **ECMA5** native implementations we hope to use are declared here.
[91] Fix | Delete
nativeForEach = ArrayProto.forEach
[92] Fix | Delete
nativeMap = ArrayProto.map
[93] Fix | Delete
nativeReduce = ArrayProto.reduce
[94] Fix | Delete
nativeReduceRight = ArrayProto.reduceRight
[95] Fix | Delete
nativeFilter = ArrayProto.filter
[96] Fix | Delete
nativeEvery = ArrayProto.every
[97] Fix | Delete
nativeSome = ArrayProto.some
[98] Fix | Delete
nativeIndexOf = ArrayProto.indexOf
[99] Fix | Delete
nativeLastIndexOf = ArrayProto.lastIndexOf
[100] Fix | Delete
nativeIsArray = Array.isArray
[101] Fix | Delete
nativeKeys = Object.keys
[102] Fix | Delete
[103] Fix | Delete
[104] Fix | Delete
# Create a safe reference to the Underscore object for use below.
[105] Fix | Delete
_ = (obj) -> new wrapper(obj)
[106] Fix | Delete
[107] Fix | Delete
[108] Fix | Delete
# Export the Underscore object for **CommonJS**.
[109] Fix | Delete
if typeof(exports) != 'undefined' then exports._ = _
[110] Fix | Delete
[111] Fix | Delete
[112] Fix | Delete
# Export Underscore to global scope.
[113] Fix | Delete
root._ = _
[114] Fix | Delete
[115] Fix | Delete
[116] Fix | Delete
# Current version.
[117] Fix | Delete
_.VERSION = '1.1.0'
[118] Fix | Delete
[119] Fix | Delete
[120] Fix | Delete
# Collection Functions
[121] Fix | Delete
# --------------------
[122] Fix | Delete
[123] Fix | Delete
# The cornerstone, an **each** implementation.
[124] Fix | Delete
# Handles objects implementing **forEach**, arrays, and raw objects.
[125] Fix | Delete
_.each = (obj, iterator, context) ->
[126] Fix | Delete
try
[127] Fix | Delete
if nativeForEach and obj.forEach is nativeForEach
[128] Fix | Delete
obj.forEach iterator, context
[129] Fix | Delete
else if _.isNumber obj.length
[130] Fix | Delete
iterator.call context, obj[i], i, obj for i in [0...obj.length]
[131] Fix | Delete
else
[132] Fix | Delete
iterator.call context, val, key, obj for own key, val of obj
[133] Fix | Delete
catch e
[134] Fix | Delete
throw e if e isnt breaker
[135] Fix | Delete
obj
[136] Fix | Delete
[137] Fix | Delete
[138] Fix | Delete
# Return the results of applying the iterator to each element. Use JavaScript
[139] Fix | Delete
# 1.6's version of **map**, if possible.
[140] Fix | Delete
_.map = (obj, iterator, context) ->
[141] Fix | Delete
return obj.map(iterator, context) if nativeMap and obj.map is nativeMap
[142] Fix | Delete
results = []
[143] Fix | Delete
_.each obj, (value, index, list) ->
[144] Fix | Delete
results.push iterator.call context, value, index, list
[145] Fix | Delete
results
[146] Fix | Delete
[147] Fix | Delete
[148] Fix | Delete
# **Reduce** builds up a single result from a list of values. Also known as
[149] Fix | Delete
# **inject**, or **foldl**. Uses JavaScript 1.8's version of **reduce**, if possible.
[150] Fix | Delete
_.reduce = (obj, iterator, memo, context) ->
[151] Fix | Delete
if nativeReduce and obj.reduce is nativeReduce
[152] Fix | Delete
iterator = _.bind iterator, context if context
[153] Fix | Delete
return obj.reduce iterator, memo
[154] Fix | Delete
_.each obj, (value, index, list) ->
[155] Fix | Delete
memo = iterator.call context, memo, value, index, list
[156] Fix | Delete
memo
[157] Fix | Delete
[158] Fix | Delete
[159] Fix | Delete
# The right-associative version of **reduce**, also known as **foldr**. Uses
[160] Fix | Delete
# JavaScript 1.8's version of **reduceRight**, if available.
[161] Fix | Delete
_.reduceRight = (obj, iterator, memo, context) ->
[162] Fix | Delete
if nativeReduceRight and obj.reduceRight is nativeReduceRight
[163] Fix | Delete
iterator = _.bind iterator, context if context
[164] Fix | Delete
return obj.reduceRight iterator, memo
[165] Fix | Delete
reversed = _.clone(_.toArray(obj)).reverse()
[166] Fix | Delete
_.reduce reversed, iterator, memo, context
[167] Fix | Delete
[168] Fix | Delete
[169] Fix | Delete
# Return the first value which passes a truth test.
[170] Fix | Delete
_.detect = (obj, iterator, context) ->
[171] Fix | Delete
result = null
[172] Fix | Delete
_.each obj, (value, index, list) ->
[173] Fix | Delete
if iterator.call context, value, index, list
[174] Fix | Delete
result = value
[175] Fix | Delete
_.breakLoop()
[176] Fix | Delete
result
[177] Fix | Delete
[178] Fix | Delete
[179] Fix | Delete
# Return all the elements that pass a truth test. Use JavaScript 1.6's
[180] Fix | Delete
# **filter**, if it exists.
[181] Fix | Delete
_.filter = (obj, iterator, context) ->
[182] Fix | Delete
return obj.filter iterator, context if nativeFilter and obj.filter is nativeFilter
[183] Fix | Delete
results = []
[184] Fix | Delete
_.each obj, (value, index, list) ->
[185] Fix | Delete
results.push value if iterator.call context, value, index, list
[186] Fix | Delete
results
[187] Fix | Delete
[188] Fix | Delete
[189] Fix | Delete
# Return all the elements for which a truth test fails.
[190] Fix | Delete
_.reject = (obj, iterator, context) ->
[191] Fix | Delete
results = []
[192] Fix | Delete
_.each obj, (value, index, list) ->
[193] Fix | Delete
results.push value if not iterator.call context, value, index, list
[194] Fix | Delete
results
[195] Fix | Delete
[196] Fix | Delete
[197] Fix | Delete
# Determine whether all of the elements match a truth test. Delegate to
[198] Fix | Delete
# JavaScript 1.6's **every**, if it is present.
[199] Fix | Delete
_.every = (obj, iterator, context) ->
[200] Fix | Delete
iterator ||= _.identity
[201] Fix | Delete
return obj.every iterator, context if nativeEvery and obj.every is nativeEvery
[202] Fix | Delete
result = true
[203] Fix | Delete
_.each obj, (value, index, list) ->
[204] Fix | Delete
_.breakLoop() unless (result = result and iterator.call(context, value, index, list))
[205] Fix | Delete
result
[206] Fix | Delete
[207] Fix | Delete
[208] Fix | Delete
# Determine if at least one element in the object matches a truth test. Use
[209] Fix | Delete
# JavaScript 1.6's **some**, if it exists.
[210] Fix | Delete
_.some = (obj, iterator, context) ->
[211] Fix | Delete
iterator ||= _.identity
[212] Fix | Delete
return obj.some iterator, context if nativeSome and obj.some is nativeSome
[213] Fix | Delete
result = false
[214] Fix | Delete
_.each obj, (value, index, list) ->
[215] Fix | Delete
_.breakLoop() if (result = iterator.call(context, value, index, list))
[216] Fix | Delete
result
[217] Fix | Delete
[218] Fix | Delete
[219] Fix | Delete
# Determine if a given value is included in the array or object,
[220] Fix | Delete
# based on `===`.
[221] Fix | Delete
_.include = (obj, target) ->
[222] Fix | Delete
return _.indexOf(obj, target) isnt -1 if nativeIndexOf and obj.indexOf is nativeIndexOf
[223] Fix | Delete
return true for own key, val of obj when val is target
[224] Fix | Delete
false
[225] Fix | Delete
[226] Fix | Delete
[227] Fix | Delete
# Invoke a method with arguments on every item in a collection.
[228] Fix | Delete
_.invoke = (obj, method) ->
[229] Fix | Delete
args = _.rest arguments, 2
[230] Fix | Delete
(if method then val[method] else val).apply(val, args) for val in obj
[231] Fix | Delete
[232] Fix | Delete
[233] Fix | Delete
# Convenience version of a common use case of **map**: fetching a property.
[234] Fix | Delete
_.pluck = (obj, key) ->
[235] Fix | Delete
_.map(obj, (val) -> val[key])
[236] Fix | Delete
[237] Fix | Delete
[238] Fix | Delete
# Return the maximum item or (item-based computation).
[239] Fix | Delete
_.max = (obj, iterator, context) ->
[240] Fix | Delete
return Math.max.apply(Math, obj) if not iterator and _.isArray(obj)
[241] Fix | Delete
result = computed: -Infinity
[242] Fix | Delete
_.each obj, (value, index, list) ->
[243] Fix | Delete
computed = if iterator then iterator.call(context, value, index, list) else value
[244] Fix | Delete
computed >= result.computed and (result = {value: value, computed: computed})
[245] Fix | Delete
result.value
[246] Fix | Delete
[247] Fix | Delete
[248] Fix | Delete
# Return the minimum element (or element-based computation).
[249] Fix | Delete
_.min = (obj, iterator, context) ->
[250] Fix | Delete
return Math.min.apply(Math, obj) if not iterator and _.isArray(obj)
[251] Fix | Delete
result = computed: Infinity
[252] Fix | Delete
_.each obj, (value, index, list) ->
[253] Fix | Delete
computed = if iterator then iterator.call(context, value, index, list) else value
[254] Fix | Delete
computed < result.computed and (result = {value: value, computed: computed})
[255] Fix | Delete
result.value
[256] Fix | Delete
[257] Fix | Delete
[258] Fix | Delete
# Sort the object's values by a criterion produced by an iterator.
[259] Fix | Delete
_.sortBy = (obj, iterator, context) ->
[260] Fix | Delete
_.pluck(((_.map obj, (value, index, list) ->
[261] Fix | Delete
{value: value, criteria: iterator.call(context, value, index, list)}
[262] Fix | Delete
).sort((left, right) ->
[263] Fix | Delete
a = left.criteria; b = right.criteria
[264] Fix | Delete
if a < b then -1 else if a > b then 1 else 0
[265] Fix | Delete
)), 'value')
[266] Fix | Delete
[267] Fix | Delete
[268] Fix | Delete
# Use a comparator function to figure out at what index an object should
[269] Fix | Delete
# be inserted so as to maintain order. Uses binary search.
[270] Fix | Delete
_.sortedIndex = (array, obj, iterator) ->
[271] Fix | Delete
iterator ||= _.identity
[272] Fix | Delete
low = 0
[273] Fix | Delete
high = array.length
[274] Fix | Delete
while low < high
[275] Fix | Delete
mid = (low + high) >> 1
[276] Fix | Delete
if iterator(array[mid]) < iterator(obj) then low = mid + 1 else high = mid
[277] Fix | Delete
low
[278] Fix | Delete
[279] Fix | Delete
[280] Fix | Delete
# Convert anything iterable into a real, live array.
[281] Fix | Delete
_.toArray = (iterable) ->
[282] Fix | Delete
return [] if (!iterable)
[283] Fix | Delete
return iterable.toArray() if (iterable.toArray)
[284] Fix | Delete
return iterable if (_.isArray(iterable))
[285] Fix | Delete
return slice.call(iterable) if (_.isArguments(iterable))
[286] Fix | Delete
_.values(iterable)
[287] Fix | Delete
[288] Fix | Delete
[289] Fix | Delete
# Return the number of elements in an object.
[290] Fix | Delete
_.size = (obj) -> _.toArray(obj).length
[291] Fix | Delete
[292] Fix | Delete
[293] Fix | Delete
# Array Functions
[294] Fix | Delete
# ---------------
[295] Fix | Delete
[296] Fix | Delete
# Get the first element of an array. Passing `n` will return the first N
[297] Fix | Delete
# values in the array. Aliased as **head**. The `guard` check allows it to work
[298] Fix | Delete
# with **map**.
[299] Fix | Delete
_.first = (array, n, guard) ->
[300] Fix | Delete
if n and not guard then slice.call(array, 0, n) else array[0]
[301] Fix | Delete
[302] Fix | Delete
[303] Fix | Delete
# Returns everything but the first entry of the array. Aliased as **tail**.
[304] Fix | Delete
# Especially useful on the arguments object. Passing an `index` will return
[305] Fix | Delete
# the rest of the values in the array from that index onward. The `guard`
[306] Fix | Delete
# check allows it to work with **map**.
[307] Fix | Delete
_.rest = (array, index, guard) ->
[308] Fix | Delete
slice.call(array, if _.isUndefined(index) or guard then 1 else index)
[309] Fix | Delete
[310] Fix | Delete
[311] Fix | Delete
# Get the last element of an array.
[312] Fix | Delete
_.last = (array) -> array[array.length - 1]
[313] Fix | Delete
[314] Fix | Delete
[315] Fix | Delete
# Trim out all falsy values from an array.
[316] Fix | Delete
_.compact = (array) -> item for item in array when item
[317] Fix | Delete
[318] Fix | Delete
[319] Fix | Delete
# Return a completely flattened version of an array.
[320] Fix | Delete
_.flatten = (array) ->
[321] Fix | Delete
_.reduce array, (memo, value) ->
[322] Fix | Delete
return memo.concat(_.flatten(value)) if _.isArray value
[323] Fix | Delete
memo.push value
[324] Fix | Delete
memo
[325] Fix | Delete
, []
[326] Fix | Delete
[327] Fix | Delete
[328] Fix | Delete
# Return a version of the array that does not contain the specified value(s).
[329] Fix | Delete
_.without = (array) ->
[330] Fix | Delete
values = _.rest arguments
[331] Fix | Delete
val for val in _.toArray(array) when not _.include values, val
[332] Fix | Delete
[333] Fix | Delete
[334] Fix | Delete
# Produce a duplicate-free version of the array. If the array has already
[335] Fix | Delete
# been sorted, you have the option of using a faster algorithm.
[336] Fix | Delete
_.uniq = (array, isSorted) ->
[337] Fix | Delete
memo = []
[338] Fix | Delete
for el, i in _.toArray array
[339] Fix | Delete
memo.push el if i is 0 || (if isSorted is true then _.last(memo) isnt el else not _.include(memo, el))
[340] Fix | Delete
memo
[341] Fix | Delete
[342] Fix | Delete
[343] Fix | Delete
# Produce an array that contains every item shared between all the
[344] Fix | Delete
# passed-in arrays.
[345] Fix | Delete
_.intersect = (array) ->
[346] Fix | Delete
rest = _.rest arguments
[347] Fix | Delete
_.select _.uniq(array), (item) ->
[348] Fix | Delete
_.all rest, (other) ->
[349] Fix | Delete
_.indexOf(other, item) >= 0
[350] Fix | Delete
[351] Fix | Delete
[352] Fix | Delete
# Zip together multiple lists into a single array -- elements that share
[353] Fix | Delete
# an index go together.
[354] Fix | Delete
_.zip = ->
[355] Fix | Delete
length = _.max _.pluck arguments, 'length'
[356] Fix | Delete
results = new Array length
[357] Fix | Delete
for i in [0...length]
[358] Fix | Delete
results[i] = _.pluck arguments, String i
[359] Fix | Delete
results
[360] Fix | Delete
[361] Fix | Delete
[362] Fix | Delete
# If the browser doesn't supply us with **indexOf** (I'm looking at you, MSIE),
[363] Fix | Delete
# we need this function. Return the position of the first occurrence of an
[364] Fix | Delete
# item in an array, or -1 if the item is not included in the array.
[365] Fix | Delete
_.indexOf = (array, item) ->
[366] Fix | Delete
return array.indexOf item if nativeIndexOf and array.indexOf is nativeIndexOf
[367] Fix | Delete
i = 0; l = array.length
[368] Fix | Delete
while l - i
[369] Fix | Delete
if array[i] is item then return i else i++
[370] Fix | Delete
-1
[371] Fix | Delete
[372] Fix | Delete
[373] Fix | Delete
# Provide JavaScript 1.6's **lastIndexOf**, delegating to the native function,
[374] Fix | Delete
# if possible.
[375] Fix | Delete
_.lastIndexOf = (array, item) ->
[376] Fix | Delete
return array.lastIndexOf(item) if nativeLastIndexOf and array.lastIndexOf is nativeLastIndexOf
[377] Fix | Delete
i = array.length
[378] Fix | Delete
while i
[379] Fix | Delete
if array[i] is item then return i else i--
[380] Fix | Delete
-1
[381] Fix | Delete
[382] Fix | Delete
[383] Fix | Delete
# Generate an integer Array containing an arithmetic progression. A port of
[384] Fix | Delete
# [the native Python **range** function](http://docs.python.org/library/functions.html#range).
[385] Fix | Delete
_.range = (start, stop, step) ->
[386] Fix | Delete
a = arguments
[387] Fix | Delete
solo = a.length <= 1
[388] Fix | Delete
i = start = if solo then 0 else a[0]
[389] Fix | Delete
stop = if solo then a[0] else a[1]
[390] Fix | Delete
step = a[2] or 1
[391] Fix | Delete
len = Math.ceil((stop - start) / step)
[392] Fix | Delete
return [] if len <= 0
[393] Fix | Delete
range = new Array len
[394] Fix | Delete
idx = 0
[395] Fix | Delete
loop
[396] Fix | Delete
return range if (if step > 0 then i - stop else stop - i) >= 0
[397] Fix | Delete
range[idx] = i
[398] Fix | Delete
idx++
[399] Fix | Delete
i+= step
[400] Fix | Delete
[401] Fix | Delete
[402] Fix | Delete
# Function Functions
[403] Fix | Delete
# ------------------
[404] Fix | Delete
[405] Fix | Delete
# Create a function bound to a given object (assigning `this`, and arguments,
[406] Fix | Delete
# optionally). Binding with arguments is also known as **curry**.
[407] Fix | Delete
_.bind = (func, obj) ->
[408] Fix | Delete
args = _.rest arguments, 2
[409] Fix | Delete
-> func.apply obj or root, args.concat arguments
[410] Fix | Delete
[411] Fix | Delete
[412] Fix | Delete
# Bind all of an object's methods to that object. Useful for ensuring that
[413] Fix | Delete
# all callbacks defined on an object belong to it.
[414] Fix | Delete
_.bindAll = (obj) ->
[415] Fix | Delete
funcs = if arguments.length > 1 then _.rest(arguments) else _.functions(obj)
[416] Fix | Delete
_.each funcs, (f) -> obj[f] = _.bind obj[f], obj
[417] Fix | Delete
obj
[418] Fix | Delete
[419] Fix | Delete
[420] Fix | Delete
# Delays a function for the given number of milliseconds, and then calls
[421] Fix | Delete
# it with the arguments supplied.
[422] Fix | Delete
_.delay = (func, wait) ->
[423] Fix | Delete
args = _.rest arguments, 2
[424] Fix | Delete
setTimeout((-> func.apply(func, args)), wait)
[425] Fix | Delete
[426] Fix | Delete
[427] Fix | Delete
# Memoize an expensive function by storing its results.
[428] Fix | Delete
_.memoize = (func, hasher) ->
[429] Fix | Delete
memo = {}
[430] Fix | Delete
hasher or= _.identity
[431] Fix | Delete
->
[432] Fix | Delete
key = hasher.apply this, arguments
[433] Fix | Delete
return memo[key] if key of memo
[434] Fix | Delete
memo[key] = func.apply this, arguments
[435] Fix | Delete
[436] Fix | Delete
[437] Fix | Delete
# Defers a function, scheduling it to run after the current call stack has
[438] Fix | Delete
# cleared.
[439] Fix | Delete
_.defer = (func) ->
[440] Fix | Delete
_.delay.apply _, [func, 1].concat _.rest arguments
[441] Fix | Delete
[442] Fix | Delete
[443] Fix | Delete
# Returns the first function passed as an argument to the second,
[444] Fix | Delete
# allowing you to adjust arguments, run code before and after, and
[445] Fix | Delete
# conditionally execute the original function.
[446] Fix | Delete
_.wrap = (func, wrapper) ->
[447] Fix | Delete
-> wrapper.apply wrapper, [func].concat arguments
[448] Fix | Delete
[449] Fix | Delete
[450] Fix | Delete
# Returns a function that is the composition of a list of functions, each
[451] Fix | Delete
# consuming the return value of the function that follows.
[452] Fix | Delete
_.compose = ->
[453] Fix | Delete
funcs = arguments
[454] Fix | Delete
->
[455] Fix | Delete
args = arguments
[456] Fix | Delete
for i in [funcs.length - 1..0] by -1
[457] Fix | Delete
args = [funcs[i].apply(this, args)]
[458] Fix | Delete
args[0]
[459] Fix | Delete
[460] Fix | Delete
[461] Fix | Delete
# Object Functions
[462] Fix | Delete
# ----------------
[463] Fix | Delete
[464] Fix | Delete
# Retrieve the names of an object's properties.
[465] Fix | Delete
_.keys = nativeKeys or (obj) ->
[466] Fix | Delete
return _.range 0, obj.length if _.isArray(obj)
[467] Fix | Delete
key for key, val of obj
[468] Fix | Delete
[469] Fix | Delete
[470] Fix | Delete
# Retrieve the values of an object's properties.
[471] Fix | Delete
_.values = (obj) ->
[472] Fix | Delete
_.map obj, _.identity
[473] Fix | Delete
[474] Fix | Delete
[475] Fix | Delete
# Return a sorted list of the function names available in Underscore.
[476] Fix | Delete
_.functions = (obj) ->
[477] Fix | Delete
_.filter(_.keys(obj), (key) -> _.isFunction(obj[key])).sort()
[478] Fix | Delete
[479] Fix | Delete
[480] Fix | Delete
# Extend a given object with all of the properties in a source object.
[481] Fix | Delete
_.extend = (obj) ->
[482] Fix | Delete
for source in _.rest(arguments)
[483] Fix | Delete
obj[key] = val for key, val of source
[484] Fix | Delete
obj
[485] Fix | Delete
[486] Fix | Delete
[487] Fix | Delete
# Create a (shallow-cloned) duplicate of an object.
[488] Fix | Delete
_.clone = (obj) ->
[489] Fix | Delete
return obj.slice 0 if _.isArray obj
[490] Fix | Delete
_.extend {}, obj
[491] Fix | Delete
[492] Fix | Delete
[493] Fix | Delete
# Invokes interceptor with the obj, and then returns obj.
[494] Fix | Delete
# The primary purpose of this method is to "tap into" a method chain,
[495] Fix | Delete
# in order to perform operations on intermediate results within
[496] Fix | Delete
the chain.
[497] Fix | Delete
_.tap = (obj, interceptor) ->
[498] Fix | Delete
interceptor obj
[499] Fix | Delete
12
It is recommended that you Edit text format, this type of Fix handles quite a lot in one request
Function