If you're after a standard library for Javascript, you could do worse than including es5-shim. Which has the advantage of being a library that (partially) implements a standard: Ecmascript 5.
> es5-shim.js and es5-shim.min.js monkey-patch a
> JavaScript context to contain all EcmaScript 5
> methods that can be faithfully emulated with a
> legacy JavaScript engine.
It provides Array::map, Array::filter, Array::reduce as defined in Ecmascript 5 along with String::trim and others, as well as replacing buggy implementations.
Previous versions of es5-shim included shims for things that cannot be correctly or completely shimmed in ES3 but those have since been separated and I now recommend including es5-shim in basically all web projects to get closer to a modern javascript in most browsers.
Sure. You could do worse than RubyJS as well. This project is implementing the standard set by the reference implementation of Ruby and its standard library. And having used Ruby a bit, I’ve come to find its standard library quite good, as dynamic languages go. So it doesn’t much matter that ES5 features are “more native”—here and now, it’s still a matter of preference.
I don't really see why RubyJS would be better than PHP.js.
And I'm definitely not saying that PHP.js should be used.
[edit] To be more specific, I really don't see the point of using a third-party library when the native methods are available. IMHO, if you choose a language, you should stick with it.
RubyJS creator here. I was just missing so many (native) methods in javascript. i liked the standard library of javascript and there is an extensive public ruby testsuite that i could use to test my implementation against. Plus i liked the idea of taking something that already works elsewhere and translate it JS, instead of coming up with my own API. IMO it's the same as using underscore/lodash, stringjs, etc, just all in the same library with the same coding standards and interoperability between classes.
I'm not a rubyist, and I can see how this can be nice for ruby developers, but IMHO, if you need javascript - use javascript.
Why add another layer of complexity and error proneness?
What happens when a different js programmer needs to review your code? Or when you need to write some Node.js code and forgot all about syntax?
"The main motive is to have a decent standard library for JavaScript" - jQuery works just fine.
Clearly jQuery isn't providing a lot of the things they are looking for in a standard library, as it is focussed on DOM manipulation and Ruby.js attempts to provide core types like Enumerables and Time.
I've never considered jQuery as a standard library, more of an interface for the DOM, especially considering that 99% of it is at most 2 steps away from the DOM.
Prototype, Underscore, jQuery, Coffescript, .... RubyJS - nobody love pure JS, when you've got a chance to write nice code(short and descriptive) - why don't use this ability? And about "different js programmer needs to review your code" - if you don't know smth then you need to study it. That's a fundament of programming world(probably not only programming))
Untrue. The ES5 standard contains most of the features required for any application (my main issue being the Date prototype which could easily be improved).
jQuery, Prototype and afaik Underscore helper functions have been wrote when the standard wasn't ready. Now that it is, developers should start using them.
This is js, just extended with some extra functionality. No different than jquery, underscore, etc. I don't see any reason for the harsh criticism, remember js is a very dynamic language that's in constant flux... We're not coding in C here.
Actually, even without jQuery, the native library for strings, arrays and numbers is usually more than enough. I might have needed something like `capitalize()` once or twice but would probably not include a whole library just for that.
Agree to disagree. The JS native library is incredibly rudimentary by "modern" standards. Even something as basic as comparing two arrays requires either hand rolling a solution or reaching out to a separate library.
A thousand times this. Javascript as a modern language for non-web things is not mature at all. The amount of date/time, string, and hash utility functions that JS simply does not have is staggering.
I do as we'll. After working in node for a bit I have come to appreciate how nice the call backs work, but I hate the fact I have to use them every where. Plus ruby has a few ways to implement callbacks which can be confusing.
Yes, as someone who really likes Ruby, this is probably my least favourite thing about it — the messy profusion of subtly-different functiony things (Procs, blocks, methods, ...).
I'm not a fan of RubyJS, but I dislike underscore for the same reason: it encourages people to use implementation specific versions fo existing ES5 standard methods [1].
I use ES5 shim instead. That way when I ditch support for IE8, I don't have to fix anything.
[1] Obviously Underscore doesn't have methods, it has utility functions attached to punctuation.
underscorejs didn't provide me String methods, Time (with timezones), some number methods, and a few iterator methods i was used to from ruby land. Also i missed the chainability across types and iterators.
I think this is really awesome. I know I can use ES5 and I don't even have to worry about old browsers because my app requires the latest to work, but I think this is more a preference thing.
Hell, I could even use JQuery for a lot of this stuff, but I really like ruby standard library and it's cleaness.
Yes. Primitives are boxed. However method arguments are only boxed when needed, which makes it as fast as normal. In the methods internally are all using JS primitives (there are some left-overs where that's not the case yet). Wrapper objects are similarly fast as extending native JS types.
Previous versions of es5-shim included shims for things that cannot be correctly or completely shimmed in ES3 but those have since been separated and I now recommend including es5-shim in basically all web projects to get closer to a modern javascript in most browsers.