Created
May 11, 2013 18:25
-
-
Save skahack/5560889 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| (-> | |
| lodash = require('lodash') | |
| ((root, _) -> | |
| class _Kernel | |
| class: 'Kernel' | |
| constructor: (v) -> | |
| @v = v | |
| @updateProperties() | |
| updateProperties: -> | |
| _args: (args) -> | |
| args = Array.prototype.slice.call(args) | |
| args.unshift(@v) | |
| return args | |
| # | |
| # Underscore's methods | |
| # | |
| functions: -> wrap _.functions(this) | |
| methods: -> @functions.apply(this, arguments) | |
| clone: -> wrap _.clone.apply(this, @_args(arguments)) | |
| tap: -> wrap _.tap.apply(this, @_args(arguments)) | |
| isEqual: -> wrap _.isEqual.apply(this, @_args(arguments)) | |
| isElement: -> wrap _.isElement.apply(this, @_args(arguments)) | |
| isEmpty: -> wrap _.isEmpty.apply(this, @_args(arguments)) | |
| isArray: -> wrap _.isArray.apply(this, @_args(arguments)) | |
| isObject: -> wrap _.isObject.apply(this, @_args(arguments)) | |
| isArguments: -> wrap _.isArguments.apply(this, @_args(arguments)) | |
| isFunction: -> wrap _.isFunction.apply(this, @_args(arguments)) | |
| isString: -> wrap _.isString.apply(this, @_args(arguments)) | |
| isNumber: -> wrap _.isNumber.apply(this, @_args(arguments)) | |
| isFinite: -> wrap _.isFinite.apply(this, @_args(arguments)) | |
| isBoolean: -> wrap _.isBoolean.apply(this, @_args(arguments)) | |
| isDate: -> wrap _.isDate.apply(this, @_args(arguments)) | |
| isRegExp: -> wrap _.isRegExp.apply(this, @_args(arguments)) | |
| isNaN: -> wrap _.isNaN.apply(this, @_args(arguments)) | |
| isNull: -> wrap _.isNull.apply(this, @_args(arguments)) | |
| isUndefined: -> wrap _.isUndefined.apply(this, @_args(arguments)) | |
| class _Collection extends _Kernel | |
| class: 'Collection' | |
| each: -> wrap _.each.apply(this, @_args(arguments)) | |
| forEach: -> @each(this, arguments) | |
| map: -> wrap _.map.apply(this, @_args(arguments)) | |
| collect: -> @map(this, arguments) | |
| reduce: -> wrap _.reduce.apply(this, @_args(arguments)) | |
| inject: -> @reduce(this, arguments) | |
| foldl: -> @reduce(this, arguments) | |
| reduceRight: -> wrap _.reduceRight.apply(this, @_args(arguments)) | |
| foldr: -> @reduceRight(this, arguments) | |
| find: -> wrap _.find.apply(this, @_args(arguments)) | |
| detect: -> @find(this, arguments) | |
| filter: -> wrap _.filter.apply(this, @_args(arguments)) | |
| select: -> @filter(this, arguments) | |
| where: -> wrap _.where.apply(this, @_args(arguments)) | |
| findWhere: -> wrap _.findWhere.apply(this, @_args(arguments)) | |
| reject: -> wrap _.reject.apply(this, @_args(arguments)) | |
| every: -> wrap _.every.apply(this, @_args(arguments)) | |
| all: -> @every(this, arguments) | |
| some: -> wrap _.some.apply(this, @_args(arguments)) | |
| any: -> @some(this, arguments) | |
| contains: -> wrap _.contains.apply(this, @_args(arguments)) | |
| include: -> @contains(this, arguments) | |
| invoke: -> wrap _.invoke.apply(this, @_args(arguments)) | |
| pluck: -> wrap _.pluck.apply(this, @_args(arguments)) | |
| max: -> wrap _.max.apply(this, @_args(arguments)) | |
| min: -> wrap _.min.apply(this, @_args(arguments)) | |
| sortBy: -> wrap _.sortBy.apply(this, @_args(arguments)) | |
| groupBy: -> wrap _.groupBy.apply(this, @_args(arguments)) | |
| countBy: -> wrap _.countBy.apply(this, @_args(arguments)) | |
| shuffle: -> wrap _.shuffle.apply(this, @_args(arguments)) | |
| toArray: -> wrap _.toArray.apply(this, @_args(arguments)) | |
| size: -> wrap _.size.apply(this, @_args(arguments)) | |
| class _Array extends _Collection | |
| _p = Array.prototype | |
| class: 'Array' | |
| updateProperties: -> | |
| super() | |
| @length = wrap @v.length | |
| pop: -> | |
| _p.pop.apply(@v, arguments) | |
| wrap @v | |
| push: -> | |
| _p.push.apply(@v, arguments) | |
| wrap @v | |
| shift: -> | |
| _p.shift.apply(@v, arguments) | |
| wrap @v | |
| unshift: -> | |
| _p.unshift.apply(@v, @_args(arguments)) | |
| wrap @v | |
| reverse: -> wrap _p.reverse.apply(@v, arguments) | |
| sort: -> wrap _p.sort.apply(@v, arguments) | |
| splice: -> wrap _p.splice.apply(@v, arguments) | |
| concat: -> wrap _p.concat.apply(@v, arguments) | |
| join: -> wrap _p.join.apply(@v, arguments) | |
| slice: -> wrap _p.slice.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| # | |
| # Underscore's methods | |
| # | |
| first: -> wrap _.first.apply(this, @_args(arguments)) | |
| head: -> @first.apply(this, arguments) | |
| take: -> @first.apply(this, arguments) | |
| initial: -> wrap _.initial.apply(this, @_args(arguments)) | |
| last: -> wrap _.last.apply(this, @_args(arguments)) | |
| rest: -> wrap _.rest.apply(this, @_args(arguments)) | |
| tail: -> @rest.apply(this, arguments) | |
| drop: -> @rest.apply(this, arguments) | |
| compact: -> wrap _.compact.apply(this, @_args(arguments)) | |
| flatten: -> wrap _.flatten.apply(this, @_args(arguments)) | |
| without: -> wrap _.without.apply(this, @_args(arguments)) | |
| union: -> wrap _.union.apply(this, @_args(arguments)) | |
| intersection: -> wrap _.intersection.apply(this, @_args(arguments)) | |
| difference: -> wrap _.difference.apply(this, @_args(arguments)) | |
| uniq: -> wrap _.uniq.apply(this, @_args(arguments)) | |
| unique: -> @uniq.apply(this, arguments) | |
| zip: -> wrap _.zip.apply(this, @_args(arguments)) | |
| object: -> wrap _.object.apply(this, @_args(arguments)) | |
| indexOf: -> wrap _.indexOf.apply(this, @_args(arguments)) | |
| lastIndexOf: -> wrap _.lastIndexOf.apply(this, @_args(arguments)) | |
| sortedIndex: -> wrap _.sortedIndex.apply(this, @_args(arguments)) | |
| _Array.range = -> wrap _.range.apply(this, arguments) | |
| class _Object extends _Collection | |
| class: 'Object' | |
| keys: -> wrap _.keys.apply(this, @_args(arguments)) | |
| values: -> wrap _.values.apply(this, @_args(arguments)) | |
| pairs: -> wrap _.pairs.apply(this, @_args(arguments)) | |
| invert: -> wrap _.invert.apply(this, @_args(arguments)) | |
| extend: -> wrap _.extend.apply(this, @_args(arguments)) | |
| pick: -> wrap _.pick.apply(this, @_args(arguments)) | |
| omit: -> wrap _.omit.apply(this, @_args(arguments)) | |
| defaults: -> wrap _.defaults.apply(this, @_args(arguments)) | |
| has: -> wrap _.has.apply(this, @_args(arguments)) | |
| class _String extends _Kernel | |
| _p = String.prototype | |
| class: 'String' | |
| charAt: -> wrap _p.charAt.apply(@v, arguments) | |
| charCodeAt: -> wrap _p.charCodeAt.apply(@v, arguments) | |
| concat: -> wrap _p.concat.apply(@v, arguments) | |
| contains: -> wrap _p.contains.apply(@v, arguments) | |
| endsWith: -> wrap _p.endsWith.apply(@v, arguments) | |
| indexOf: -> wrap _p.indexOf.apply(@v, arguments) | |
| lastIndexOf: -> wrap _p.lastIndexOf.apply(@v, arguments) | |
| localeCompare: -> wrap _p.localeCompare.apply(@v, arguments) | |
| match: -> wrap _p.match.apply(@v, arguments) | |
| replace: -> wrap _p.replace.apply(@v, arguments) | |
| search: -> wrap _p.search.apply(@v, arguments) | |
| slice: -> wrap _p.slice.apply(@v, arguments) | |
| split: -> wrap _p.split.apply(@v, arguments) | |
| startsWith: -> wrap _p.startsWith.apply(@v, arguments) | |
| substr: -> wrap _p.substr.apply(@v, arguments) | |
| substring: -> wrap _p.substring.apply(@v, arguments) | |
| toLocaleLowerCase: -> wrap _p.toLocaleLowerCase.apply(@v, arguments) | |
| toLocaleUpperCase: -> wrap _p.toLocaleUpperCase.apply(@v, arguments) | |
| toLowerCase: -> wrap _p.toLowerCase.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| toUpperCase: -> wrap _p.toUpperCase.apply(@v, arguments) | |
| trim: -> wrap _p.trim.apply(@v, arguments) | |
| valueOf: -> wrap _p.valueOf.apply(@v, arguments) | |
| class _Number extends _Kernel | |
| _p = String.prototype | |
| class: 'Number' | |
| toExponential: -> wrap _p.toExponential.apply(@v, arguments) | |
| toFixed: -> wrap _p.toFixed.apply(@v, arguments) | |
| toLocaleString: -> wrap _p.toLocaleString.apply(@v, arguments) | |
| toPrecision: -> wrap _p.toPrecision.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| valueOf: -> wrap _p.valueOf.apply(@v, arguments) | |
| # | |
| # Underscore's methods | |
| # | |
| times: -> wrap _.times.apply(this, @_args(arguments)) | |
| class _Function extends _Kernel | |
| _p = Function.prototype | |
| class: 'Function' | |
| apply: -> wrap _p.apply.apply(@v, arguments) | |
| call: -> wrap _p.call.apply(@v, arguments) | |
| isGenerator: -> wrap _p.isGenerator.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| # | |
| # Underscore's methods | |
| # | |
| bind: -> wrap _.bind.apply(this, @_args(arguments)) | |
| bindAll: -> wrap _.bindAll.apply(this, @_args(arguments)) | |
| partial: -> wrap _.partial.apply(this, @_args(arguments)) | |
| memoize: -> wrap _.memoize.apply(this, @_args(arguments)) | |
| delay: -> wrap _.delay.apply(this, @_args(arguments)) | |
| defer: -> wrap _.defer.apply(this, @_args(arguments)) | |
| throttl: -> wrap _.throttle.apply(this, @_args(arguments)) | |
| debounc: -> wrap _.debounce.apply(this, @_args(arguments)) | |
| once: -> wrap _.once.apply(this, @_args(arguments)) | |
| after: -> wrap _.after.apply(this, @_args(arguments)) | |
| wrap: -> wrap _.wrap.apply(this, @_args(arguments)) | |
| compose: -> wrap _.compose.apply(this, @_args(arguments)) | |
| class _Boolean extends _Kernel | |
| class: 'Boolean' | |
| class _Date extends _Kernel | |
| _p = Date.prototype | |
| class: 'Date' | |
| getDate: -> wrap _p.getDate.apply(@v, arguments) | |
| getDay: -> wrap _p.getDay.apply(@v, arguments) | |
| getFullYear: -> wrap _p.getFullYear.apply(@v, arguments) | |
| getHours: -> wrap _p.getHours.apply(@v, arguments) | |
| getMilliseconds: -> wrap _p.getMilliseconds.apply(@v, arguments) | |
| getMinutes: -> wrap _p.getMinutes.apply(@v, arguments) | |
| getMonth: -> wrap _p.getMonth.apply(@v, arguments) | |
| getSeconds: -> wrap _p.getSeconds.apply(@v, arguments) | |
| getTime: -> wrap _p.getTime.apply(@v, arguments) | |
| getTimezoneOffset: -> wrap _p.getTimezoneOffset.apply(@v, arguments) | |
| getUTCDate: -> wrap _p.getUTCDate.apply(@v, arguments) | |
| getUTCDay: -> wrap _p.getUTCDay.apply(@v, arguments) | |
| getUTCFullYear: -> wrap _p.getUTCFullYear.apply(@v, arguments) | |
| getUTCHours: -> wrap _p.getUTCHours.apply(@v, arguments) | |
| getUTCMilliseconds: -> wrap _p.getUTCMilliseconds.apply(@v, arguments) | |
| getUTCMinutes: -> wrap _p.getUTCMinutes.apply(@v, arguments) | |
| getUTCMonth: -> wrap _p.getUTCMonth.apply(@v, arguments) | |
| getUTCSeconds: -> wrap _p.getUTCSeconds.apply(@v, arguments) | |
| setDate: -> | |
| _p.setDate.apply(@v, arguments) | |
| wrap @v | |
| setFullYear: -> | |
| _p.setFullYear.apply(@v, arguments) | |
| wrap @v | |
| setHours: -> | |
| _p.setHours.apply(@v, arguments) | |
| wrap @v | |
| setMilliseconds: -> | |
| _p.setMilliseconds.apply(@v, arguments) | |
| wrap @v | |
| setMinutes: -> | |
| _p.setMinutes.apply(@v, arguments) | |
| wrap @v | |
| setMonth: -> | |
| _p.setMonth.apply(@v, arguments) | |
| wrap @v | |
| setSeconds: -> | |
| _p.setSeconds.apply(@v, arguments) | |
| wrap @v | |
| setTime: -> | |
| _p.setTime.apply(@v, arguments) | |
| wrap @v | |
| setUTCDate: -> | |
| _p.setUTCDate.apply(@v, arguments) | |
| wrap @v | |
| setUTCFullYear: -> | |
| _p.setUTCFullYear.apply(@v, arguments) | |
| wrap @v | |
| setUTCHours: -> | |
| _p.setUTCHours.apply(@v, arguments) | |
| wrap @v | |
| setUTCMilliseconds: -> | |
| _p.setUTCMilliseconds.apply(@v, arguments) | |
| wrap @v | |
| setUTCMinutes: -> | |
| _p.setUTCMinutes.apply(@v, arguments) | |
| wrap @v | |
| setUTCMonth: -> | |
| _p.setUTCMonth.apply(@v, arguments) | |
| wrap @v | |
| setUTCSeconds: -> | |
| _p.setUTCSeconds.apply(@v, arguments) | |
| wrap @v | |
| toDateString: -> wrap _p.toDateString.apply(@v, arguments) | |
| toLocaleDateString: -> wrap _p.toLocaleDateString.apply(@v, arguments) | |
| toLocaleString: -> wrap _p.toLocaleString.apply(@v, arguments) | |
| toLocaleTimeString: -> wrap _p.toLocaleTimeString.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| toTimeString: -> wrap _p.toTimeString.apply(@v, arguments) | |
| toUTCString: -> wrap _p.toUTCString.apply(@v, arguments) | |
| valueOf: -> wrap _p.valueOf.apply(@v, arguments) | |
| class _RegExp extends _Kernel | |
| _p = RegExp.prototype | |
| class: 'RegExp' | |
| updateProperties: -> | |
| super() | |
| @global = @v.global | |
| @ignoreCase = @v.ignoreCase | |
| @lastIndex = @v.lastIndex | |
| @multiline = @v.multiline | |
| @source = @v.source | |
| exec: -> wrap _p.exec.apply(@v, arguments) | |
| test: -> wrap _p.test.apply(@v, arguments) | |
| toString: -> wrap _p.toString.apply(@v, arguments) | |
| wrap = (obj) -> | |
| klass = 'Kernel' | |
| klass = 'Object' if _.isObject(obj) | |
| klass = 'Array' if _.isArray(obj) | |
| klass = 'String' if _.isString(obj) | |
| klass = 'Number' if _.isNumber(obj) | |
| klass = 'Function' if _.isFunction(obj) | |
| klass = 'Boolean' if _.isBoolean(obj) | |
| klass = 'Date' if _.isDate(obj) | |
| klass = 'RegExp' if _.isRegExp(obj) | |
| new wrap[klass](obj) | |
| wrap.Kernel = _Kernel | |
| wrap.Object = _Object | |
| wrap.Array = _Array | |
| wrap.String = _String | |
| wrap.Number = _Number | |
| wrap.Function = _Function | |
| wrap.Boolean = _Boolean | |
| wrap.Date = _Date | |
| wrap.RegExp = _RegExp | |
| root.wrap = wrap | |
| )(this, lodash) | |
| $$ = wrap | |
| )() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment