Meteor uses a very dated 1.5.2 version of Underscore. Two years old this Sept and missing a lot of great stuff that is in the current 1.8.2 library.
Can the package be updated?
You can update the version used in your app, though not the version used by Meteor itself. See this GitHub issue.
The easiest solution is to just replace Underscore with Lodash, which has even more features than the latest Underscore. Per this thread, it’s this easy:
meteor add alethes:lodash
And in your startup code:
// Use lodash instead of underscore
_ = lodash;
If you prefer the latest Underscore instead of Lodash, it looks like at the moment you’ll need to download the file from underscorejs.org and save it into either your lib
or client/compatibility
folder. It should execute after Meteor’s libraries themselves load, and hijack the _
variable. You can also initialize it with _.noConflict()
, in which case you can let _
stay with Meteor’s version and you can assign the new Underscore to something else, e.g. underscore = _.noConflict();
.
I should probably mention that either of these solutions will leave you with both libraries (Meteor’s old version of Underscore, and the new library you’re using instead) downloading to the client. Until Meteor itself upgrades (see GitHub issue above), that is unavoidable.
My solution using lodash with Meteor ES2015:
meteor npm i lodash --save
and import lodash /imports/startup/client/index.js:
import lodash from 'lodash';
window._ = lodash;
Regards, Nicholls
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With