The Science of Programming/SwayPresentations/Objects/Examples

Examples

How about with?

   function with(obj,$actions)
       {
       $actions . context = obj;
       force($actions);
       }

Let's create an object:

   function f(x) { var y = x + 1; this;}
   
   var o = f(3);

Now let's modify its slots:

   with (o)
       {
       x = 10;
       y = 13;
       }

Did it work?

   inspect(o . x);
   inspect(o . y);

Output:

   o . x is 10
   o . y is 13



Next Previous Top