Commit Graph

161 Commits

Author SHA1 Message Date
Jeremy Ashkenas
d855def438 adding an _.mixin utility function that allows you to add functions to Underscore (also used internally) 2010-02-24 13:44:46 -05:00
Jeremy Ashkenas
c23b2ce717 added documentation for _.times 2010-02-24 13:09:08 -05:00
Jeremy Ashkenas
65d2c30312 don't use root as the default 'this' for a bound function, use an empty object instead. 2010-02-24 12:57:26 -05:00
Jeremy Ashkenas
d7acbca2ce reverted _.buildLookup, restoring _.without to it's previous implementation, adding a test for object identity 2010-02-24 12:53:35 -05:00
Jeremy Ashkenas
412d2e4486 avoiding isFunction in _.include 2010-02-24 12:47:40 -05:00
Jeremy Ashkenas
7824d63ce8 make the new faster isEmpty a little safer too 2010-02-24 12:43:57 -05:00
Jeremy Ashkenas
2c8fbe7875 remove the advanced_optimizations concessions and the advanced_optimizations rake task. Simple will do. 2010-02-24 12:16:45 -05:00
Jeremy Ashkenas
69bb3490b3 camelcase conventions 2010-02-24 12:10:07 -05:00
Jeremy Ashkenas
39024c35a6 waypoint commit on the big merge 2010-02-24 12:03:08 -05:00
Jeremy Ashkenas
2ec05e758b merging ratbeard/closure 2010-02-24 11:45:05 -05:00
Jeremy Ashkenas
a2aab7c699 merging ratbeard's numerous improvements 2010-02-24 11:38:27 -05:00
Jeremy Ashkenas
875633141a merging rlfletchers branch with a safer _.template when the template delimiter includes RegExp characters. 2010-02-24 11:03:47 -05:00
Rick Fletcher
3482ec1259 Escape template delimiters before using them in a RegExp 2010-02-23 23:47:28 -08:00
Rick Fletcher
38a82591b1 Added failing test for quotes in statements with regex-significant characters in tokens 2010-02-23 23:44:25 -08:00
Rick Fletcher
625adb81a3 Added tests for templates with regex-significant characters in their delimiters 2010-02-23 23:41:51 -08:00
Mike Frawley
b8fd129130 only initWrapper() once. make wrapper constructor accessable as _._wrapper.
Previously, there was no way to get at the OO wrapper object.
So if a user added a custom method on to _, or defined a custom
alias, it would not be reflected in the wrapper.  Now it is at
least possible, though there is no API to do it.  I alluded to
making one in my commit that added _.alias() (which I recently reverted,
as it added weight to the stripped version), but honestly I think
the wrapping behavior should go in to a seperate library, not because
it is bad, but because it is an awesome pattern that I want to use
on objects other than underscore.
2010-02-23 18:20:42 -06:00
Mike Frawley
c9b41a4996 modify rakefile build_advanced to strip off my call to _.initWrapper() 2010-02-23 18:14:54 -06:00
Mike Frawley
f591f68546 make _.initWrapper() that builds the wrapper prototye
The intention is that underscore Consumers MUST call _.initWrapper()
in their code to allow the OO style usage, or a runtime error is thrown.
This would break backwards compatability, so for the moment I call
initWrapper myself at the end of underscore.

However, if I comment out my call to initWrapper and don't call it
in user code, then the compiler can strip an empty underscore with
no user code from 2137 -> 100 bytes.  Making the user explicitly say
they want OO wrapping is the only way to achieve this, otherwise the
compiler will always keep the OO wrapper code around.
2010-02-23 18:04:47 -06:00
Mike Frawley
1cf73c5474 Re-arrange baseline setup section.
Put all variable declartions in a row, so they can all be
chained together with commas by compiler.

Move wrapper creation code down in OO section.  Not necissary
for `var wrapper` to be defined when _ constructor is defined.
Preparing way to make OO wrapping optional..
2010-02-23 17:39:22 -06:00
Mike Frawley
59d383c151 Revert "Create #alias method, callable on any object, _ by default."
This reverts commit c43de549ba.

Conflicts:

	test/objects.js
2010-02-23 17:26:32 -06:00
Mike Frawley
164e19c121 use var native_reduceRight etc. variables instead of Native = { reduceRight: ... }
This way we only get the native versions of functions we use.
Will make testing non-native versions as we can't just swap do `_.Native = {}`,
but this wouldn't have worked for `isArray` and `keys` anyways, as these are
looked up on initialization, so I think the solution is to have an init()
method on underscore where we will re-initialize functions and try and use
native versions then
2010-02-23 17:13:18 -06:00
Mike Frawley
b5449ca89a Add rake task to build with closure advanced optimizations.
You would use this to compile your code _with_ underscore, to
remove all those dead underscore functions you don't use.

Slight tweak to code to `root._` code to get working, and must
remove anonymous wrapper function for current closure compiler to
remove dead code.
2010-02-23 17:01:18 -06:00
Mike Frawley
31f0f8c54c make a local variable that points to Array.prototype since the former is not min'd down.
Won't effect gzip size, but reduces min size.  Saves about:

15 bytes per instance * 13 instances ≅ 200 bytes
2010-02-22 16:02:36 -06:00
Mike Frawley
bb250e7205 Much better strategy for calling native Array methods.
Compare an object's function with === to the native
version before calling it.  That is, don't just assume that
because an object has a 'filter' property thats a function,
that we should call that in _.filter().

Expose the native methods found as _.native

On the way towards being able to turn off native implementations,
though there are tradeoffs...
2010-02-22 15:50:01 -06:00
Mike Frawley
b774bf7ca9 delegate to ECMA5 native Array.isArray if available 2010-02-22 14:37:54 -06:00
Mike Frawley
5a5e14d7a4 add #times utility method.
_(3).times(alert)

added tests and internal docs
2010-02-17 10:21:59 -06:00
Mike Frawley
263b1ee92d add #buildLookup method to turn collection in to a fast lookup hash
implement #without in terms of it
add tests and internal docs
2010-02-17 10:12:22 -06:00
Mike Frawley
1b1943b0ca implement include in terms of detect 2010-02-17 09:53:36 -06:00
Mike Frawley
76bbfddd95 our #reduceRight delegates to #reduce after reversing.
no need to reimplement it.

also, reduceRight is worthless :)
2010-02-17 09:51:38 -06:00
Mike Frawley
130e860ecf improve #isEmpty implementation. add 2 tests 2010-02-17 09:48:29 -06:00
Mike Frawley
386ee8ade9 add reference to underscore.js on docs page, since this is a good place to play around with it in the console 2010-02-17 09:45:24 -06:00
Mike Frawley
c43de549ba Create #alias method, callable on any object, _ by default.
While I'm not a fan of making abstractions where a simpe solution
exists, I think this is good as it makes a public API for extending
underscore, therefore making it "ok" to make your own alias names.

Also give us some future proofing in case we ever add in hooks on
method definition. For example, right now if you add a method
or make an alias in user code, it isn't added to the wrapper prototype.

Added tests and inline docs, no external docs
2010-02-17 09:41:18 -06:00
Mike Frawley
c4daac089b delegate to native Object.keys in nightlies 2010-02-17 09:26:34 -06:00
Mike Frawley
7ec8d12d6c rename underscore methods after the native [] method names, aliases for ruby versions
Even though the native methods have worse names (forEach, every, some),
since this library is trying to smooth over the native language it makes
more sense to use the native names, and provide aliases for more sensible
names from other languages, not the other way around.

Note this doesn't change any external usage, it just makes more sense.

This should also be useful for abstraction purposes for building underscore
functions, something like:

  addFn('some', {has_native: true, our_version: function () {...}})

this way we could feature detect on load for native versions and build a
function, and also have the option to turn off native versions for testing
our implementation.

I Also standardized the comments to look like:
  Delegates to JavaScript 1.x's native y if available.
2010-02-17 09:23:38 -06:00
Mike Frawley
59a4f49bfa Make internal var each = _.each
We use it everwhere, so this should be a slight speedup
but make code more readable
2010-02-17 09:05:45 -06:00
Jeremy Ashkenas
11e7af06e9 close that iframe document after writing to it 2010-02-08 07:12:40 -05:00
Jeremy Ashkenas
d01bb56833 adding type tests across iframes for all isType functions 2010-02-05 08:22:40 -05:00
Jeremy Ashkenas
5b5ee87c7a Underscore 0.5.8, with collection functions that once again work on NodeLists and HTMLCollections 2010-01-28 00:55:41 -05:00
Jeremy Ashkenas
21f37e43a1 adding duck typing section so that it's not unexpected 2010-01-27 14:05:27 -05:00
Jeremy Ashkenas
30858c50a8 added suggested speed boost for isNumber 2010-01-20 13:50:08 -05:00
Jeremy Ashkenas
52ac3db77c Underscore 0.5.7 is on the books 2010-01-20 13:17:28 -05:00
Jeremy Ashkenas
7ec091cc55 safer isArguments function -- make sure we're not dealing with strings or functions 2010-01-20 12:45:32 -05:00
Jed Schmidt
4a94246fd1 added obj.calle check to isArguments, to prevent misfiring for typeof String 2010-01-20 10:18:45 -07:00
Jeremy Ashkenas
7d9e603be8 Underscore 0.5.6, with custom template delimiters 2010-01-18 12:45:04 -05:00
noah
94195e661d Made _.template delimeters customizable 2010-01-15 23:25:52 -05:00
Jeremy Ashkenas
4f1a72da51 update docs to mention native 'reduce' -- but it's JS 1.8, not 1.6 2010-01-14 09:39:58 -05:00
Jeremy Ashkenas
cda9099a21 Underscore 0.5.5, with a fix for OOP-wrapping in MobileSafari, thanks to terrcin. 2010-01-09 19:34:32 -05:00
Jeremy Ashkenas
6866ffb840 adding a test for single quotes in templates 2010-01-05 11:28:29 -05:00
Jeremy Ashkenas
0a8a4834b2 Underscore 0.5.4 -- bugfix for single quotes in _.template strings 2010-01-05 11:26:14 -05:00
Jeremy Ashkenas
fde8b1f63f Underscore 0.5.3 2010-01-04 11:34:26 -05:00