Quote Originally Posted by Maian
Correction: everything except literal numbers are objects in JS. So there's no way to add 1.add(2) functionality to the language, except to do something like (new Number(1)).add(2).

EDIT: "var x = 1; alert(x.add(2));" also works
Can you do operator overloading in Javascript?

Another Ruby example:

Code:
class Putty
  attr_reader :weight

  def initialize(weight = 10)
    @weight = weight
  end

  def + (more_putty)
    Putty.new(@weight + more_putty.weight)
  end

end

first_blob = Putty.new  #=> @weight = 10
second_blob = Putty.new #=> @weight = 10

big_blob = first_blob + second_blob 

big_blob #=> @weight = 20
Sure you could use .add() to get the same effect, or you could use functions and an associative array instead if you like, all the same result.

Though a + b looks nicer than a.add(b) or add(a, b) or (add a b) imo

Douglas