POV-Ray : Newsgroups : povray.pov4.discussion.general : Next Generation SDL: What's wrong with Lua, JavaScript, ... : Re: Next Generation SDL: What's wrong with Lua, JavaScript, ... Server Time
21 Apr 2024 06:51:31 EDT (-0400)
  Re: Next Generation SDL: What's wrong with Lua, JavaScript, ...  
From: MessyBlob
Date: 11 Apr 2009 21:45:01
Message: <web.49e146b9e7a64ad8addfbead0@news.povray.org>
"clipka" <nomail@nomail> wrote:
> "MessyBlob" <nomail@nomail> wrote:
> > Doesn't JavaScript have the ability to assign properties [...]
> >
> > Sph = new Sphere( {
> >   radius: 1,
> >   position: [0,0,1]
> > } );

> A host of languages has this.
> The problem is still the scope: However you toss and turn it, you can't just
> go ahead and do some stuff in the new object's scope (or "namespace" or
> however you want to call it) without some added hassle.
> The problem is that all mainstream languages do initialization of an
> object by passing some expressions as parameters, with the expressions
> being evaluated in the scope of the calling block. Plus they're
> evaluated before the object is created, so can't have side effects on
> the object.

The class defines default property values in its constructor. Then when you
create instances, you can optionally assign values to the properties. So the
examples of 'radius' and 'position' are the names of the properties defined in
the class. I think this is a very elegant way of instantiating objects, with
syntax that is very similar to POV-Ray SDL.

Can you explain your thoughts on what the problem will be with this approach?
Are you thinking of transformations? Method-triggering property
assignments ('set' methods) achieve this, e.g. a "translate: [1,0,0]" property
would call ".doTranslate([1,0,0])" to change the transform matrix just like the
current SDL parser would. As I understand it, properties are set *after* object
instantiation, even if they are evaluated before the instantiation.

The JavaScript way seems better than the 'predefined parameters' approach of
most other languages, even when (with other languages) overloaded constructors
(variants that have different types or number of parameters) are specified in
the class.

One weakness I see with this approach, is when POV-Ray SDL containers may have a
number of children, e.g. with CSG, it might be better to use a ".add(new ...)"
method call to add child objects to the list.

(With apologies if I'm going over unnecessary background information; I don't
know how much you, or a typical reader, knows about JavaScript or OO).

Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.