From: Robert Klemme Date: 2005-02-11T01:40:03+09:00 Subject: Re: Class of the Instance [was Re: Building a Better Functor] "Adriano Ferreira" schrieb im Newsbeitrag news:73ddeb6c050210080447cafa7f@mail.gmail.com... > Robert Klemme said: > > JavaScript has no classes as far as I know. Ruby has classes and > from that alone it's obvious that it's a bit more complicated. > > Indeed JavaScript supports object orientation based on prototypes > rather than classes. This is an idea borrowed by a Smalltalk-like > language called Self and other sources of inspirations. > > Don't underestimate JavaScript though or prototype-based inheritance. I didn't intend to. It's just that Ruby has classes while JS has not. > Most things that can be done with classes can be done with prototypes. > Some things are straightforward with prototypes: delegation, addition > of a few methods or properties to one or a few instances. > > The obvious thing with JavaScript is that it lacks syntactic sugar to > make prototype construction more legible and distinguishable. Most > JavaScript code out there are lame and don't use object programming. > But the real point is that writing object code in JavaScript can be > pretty complicated and likely much less legible than in Ruby. Btw: class JavaScript def method_missing(s,*a,&b) if /^(.*)=$/ =~ s.to_s class <> f=JavaScript.new => # >> f.foo= lambda { puts "world" } => # >> f.bar= lambda { puts "hello" } => # >> f.bar; f.foo hello world => nil :-) Kind regards robert