Re: [XBL] ECMAScript Syntax

Using ( ) in ({ ...}) is mostly convention (ie. evaluate all inside { },
like you would with say x = (3 + (4 * 3)) ).

Getter and setter trigger specific behaviors when you try to get or set a
property. Try:

<html>
<script>
 test = {
      _memory: 0,
      get memory() {
        alert("memory is " + this._memory);
        return this._memory;
      },
      set memory(value) {
        var newValue = parseInt(value, 10);
        this._memory = newValue * Math.random();
      }
}
test.memory; //gets
test.memory = 52; //sets
test.memory; //gets

</script>
</html>

On 12/8/06, Cyril Concolato <cyril.concolato@enst.fr> wrote:
>
>  Hi Marcos,
>
> Marcos Caceres a écrit :
>
> Cyril raises an interesting point there regarding implementations and how
> they should be handled by scripting langauges within the context of XBL. For
> ECMAScript, it might be nice to write the constructor without using the old
> ({ ... }). Can I do the following?:
>
> <implemenation>
>  //where "this" is the scope of this implementation
>  this.x = 1234;
> this._y = 4321;
> this.funky = function(){...}
> this._helper = {( functionName: function() { return true; })}
> </implemenation>
>
> Exactly.
>
>
> Regarding getters and setters, there is a reference and explanation as
> part of the example (please see section 2.3 [1]).
>
> Thanks Marcos. I had read the link but did not understand it. Actually,
> the link [2] is more interesting than [1]. It describes the syntax
>
> objectName = {property_1:value_1, property_2:value_2, ..., property_n:value_n}
>
> which explains the use of ":".
>
> Given that I still have two questions (not specifically related to XBL):
>  - why get and set do not use ':' ? I guess getter and setter are
> particular properties and it's just a question of syntax
>  - what is the use of "(" in ({ ... }).
>
> Regards,
>
> Cyril
>
> [2]
> http://developer.mozilla.org/en/docs/Core_JavaScript_1.5_Guide:Creating_New_Objects:Using_Object_Initializers
>
> Marcos
> [1]
> http://dev.w3.org/cvsweb/~checkout~/2006/xbl2/Overview.html#the-implementation<http://dev.w3.org/cvsweb/%7Echeckout%7E/2006/xbl2/Overview.html#the-implementation>
>
> On 12/8/06, Cyril Concolato <cyril.concolato@enst.fr > wrote:
> >
> > Hi Marcos,
> >
> > Marcos Caceres a écrit :
> > > Cyril,
> > > That is standard notation for ECMAScript. Try it in your browser:
> > > <html>
> > > <script>
> > > test = ({
> > > functionName: function() {
> > >       alert("test");
> > > }
> > > })
> > >
> > > test.functionName();
> > > </script>
> > > </html>
> > >
> > > I think it is beyond the scope of the XBL spec to contain such
> > > definitions. Please let us know if you are satisfied with this
> > response.
> > >
> > Thanks for the answer. I did not know that notation. It must be some
> > object-oriented syntax. I agree that XBL does not need to redefine
> > ECMAScript syntax. The question is: Is the ECMAScript syntax in the
> > 'implementation' element free like:
> > <implementation>
> > foo = 1;
> > </implementation>
> >
> > or shall/should it obey some specific ECMAScript syntax (as all the
> > examples in the specification suggest), i.e. start with ({, contain only
> > fonction declarations, and end with }).
> >
> > If the syntax is free, please say so in the specification. If not,
> > please give link to specifics constructs allowed from the ECMAScript
> > specification. This would satisfy me.
> >
> > Regards,
> >
> > Cyril
> > >
> > > Regards,
> > > Marcos
> > >
> > > -----Original Message-----
> > > From: public-appformats-request@w3.org
> > > [mailto: public-appformats-request@w3.org] On Behalf Of Cyril
> > Concolato
> > > Sent: Thursday, 7 December 2006 2:01 AM
> > > To: WAF WG (public)
> > > Subject: [XBL] ECMAScript Syntax
> > >
> > >
> > > Dear XBL experts,
> > >
> > > This email comments on the 7 September 2006 LCWD of XBL 2.0.
> > >
> > > In many examples in the specification, in particular in Section 2.3, a
> > > syntax for ECMAScript definition of functions is used:
> > >
> > > <implementation>
> > > ({
> > > functionName: function() {
> > > }
> > > })
> > > </implementation>
> > >
> > > Is this standard ECMAScript notation ? Could you explain it or provide
> > a
> > >
> > > link to it ? What is the meaning of "({" ?
> > > The get/set fonction in that section don't use the ':' ? Is it a typo
> > ?
> > > If yes please fix it, otherwise highlight and explain this difference
> > > with the other functions.
> > >
> > > Cyril Concolato
> > >
> > >
> > >
> > >
> > >
> > >
> >
> >
>
>
> --
> Marcos Caceres
> http://datadriven.com.au
>
>
>


-- 
Marcos Caceres
http://datadriven.com.au

Received on Thursday, 7 December 2006 16:30:50 UTC