1

Are there any frameworks/wrapper out there that gives us rubyish javascript?

Instead of the usual for() {} loop gives us the object.each {} loop like in Ruby?

Since javascript could be used in web browsers I do want to use it for the server side too, but I do like ruby syntax far more.

4 Answers 4

2

The Prototype library, having been developed by guys very close to Ruby on Rails, has a very Ruby-ish feel. It uses Ruby lingo (like mixins); for instance, the Enumerable mixin (which Prototype mixes in to arrays by default) adds the each method to an array, so you can do this:

["sample", "array"].each(function (item) {
    console.log(item);
});
Sign up to request clarification or add additional context in comments.

Comments

2

look up jQuery. it has a

$('.css-selector').each(function(i){
 //do stuff
});

Ref: http://api.jquery.com/jQuery.each/

Comments

2

You might want to checkout JS.Class - Ruby-style JavaScript. From the docs,

JS.Class is a set of tools designed to make it easy to build robust object-oriented programs in JavaScript. It’s based on Ruby, and gives you access to Ruby’s object, module and class systems, some of its reflection and metaprogramming facilities, and a few of the packages from its standard library. It also provides a powerful package manager to help load your applications as efficiently as possible.

It comes with a well packaged standard library including modules and classes such as

  • Enumerable
  • Hash
  • Set
  • Observable
  • Command

The Enumerable module, for instance, is comparable to that in Ruby, and includes methods like

all
any
collect
drop
findAll
forEach
grep
partition
reject
select
zip

Comments

0

Here's a post by Ken Egozi which discusses adding .forEach and other helpers to the array prototype.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.