On Dec 6, 2005, at 8:20 PM, Adam Wolff wrote:
This is actually just a quirk in the compiler -- it emits warnings for
  el.notthere

but not for
  el[ "notthere" ]

This quirk is there specifically so that there's a warning-free way to test for the presence of an attribute.

In standard JavaScript, you can do this with the 'in' relation:
  if ('notthere' in el) ...
but OpenLaszlo JavaScript don't implement 'in'.

Why doesn't OpenLaszlo JavaScript implement 'in'? I'm not sure, actually. JavaScript doesn't allow 'in' inside an initializer in a 'for' expression, and goes through all kinds of hoops to prevent it (http://www.mozilla.org/js/language/grammar14.html), presumably because of some kind of ambiguity having to do with:
  for (var index in sequence) ...
  for (var index = expr; ...; ...) ...
if expr contains an 'in'. JavaCC is an RDP and can enforce this with inherited attributes (implemented as RDP parameters); it's not incredibly tricky like it is with a shift/reduce parser such as bison/ yacc. When I was implementing the compiler I just didn't have time even to implement it with inherited attributes, but now I don't even see what the ambiguity is.

People used this as a shortcut for sending events in code, but I think the best form here is declare the event as null (until we get tucker's <event> tag) This has no major runtime impact since literal class attribute values
with no setter are stored on the class prototype.

<node>
   <attribute name="time" setter="setTime(time)"/>
   <attribute name="ontime" value="null"/>

That way you can write
   if (ontime) this.ontime.sendEvent();

and it won't cause warnings. You're also guaranteed that the ontime slot will not get set to null after the event has been created, so it's safe.

A




On Nov 9, Jim Grandy wrote:

A particular question about how to implement setters. Here's an edited version
of the example from the DevGuide (Chapter 25, Section 5.5):

<node>
   <attribute name="time" setter="setTime(time)"/>

   <method name="setTime" args="t">
     if (!this.isinited) {  this.time = t;  return;  }

     // do some custom stuff here
     this.time = t;

     if (ontime) this.ontime.sendEvent();
   </method>
</node>

In certain cases, I'm seeing a runtime error with code similar to this, saying
that 'ontime' is not a defined property of the given object.

Grepping through the LPS sources, I've seen a different way of calling the
event handler:

    if (this['ontime'])) this.ontime.sendEvent();

When I use this idiom, I don't get the error. This makes sense to me -- if no one has declared an event for this attribute, it shouldn't be defined. But maybe I'm not understanding things and there's another reason the documented
idiom isn't working for me.

Anyone care to comment?

jim



_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user
_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

_______________________________________________
Laszlo-user mailing list
[email protected]
http://www.openlaszlo.org/mailman/listinfo/laszlo-user

Reply via email to