RE: [XBL] Clarification: addBinding() and the xbl:script element

Awesome, thanks for clarifying that. If it is explicitly clear in the spec,
I must have missed it somewhere along the way. Thanks.
Marcos  

-----Original Message-----
From: Ian Hickson [mailto:ian@hixie.ch] 
Sent: Saturday, 6 January 2007 7:56 AM
To: Marcos Caceres
Cc: public-appformats@w3.org
Subject: Re: [XBL] Clarification: addBinding() and the xbl:script element

On Tue, 28 Nov 2006, Marcos Caceres wrote:
>
> The following relates to Section 3.5 - Binding Attachment Model.  Can 
> you please clarify the following:
> 
> If I attach a binding to an element using addBiding() (or using CSS 
> '-xbl-binding:'), can I still call functions defined in an xbl:script 
> element from within the implementation of a binding?

Yes. The <xbl:script> element is evaluated in the binding document's 
global scope, and the binding's code itself is also run in the binding 
document's global scope. This seems very explicitly stated in the spec. 


> The 6 steps defined in section 3.5 do not specify if xbl:script elements 
> in bounding documents are evaluated and made available in such 
> situations.

It's not clear to me why section 3.5 would need to mention <xbl:script> 
elements at all. Could you elaborate?


> <xbl ...>
> <script> 
>                 var count = 0; 
>                 function counterInc(){ return count++;}
> <script>
> <binding id="magicButton">
>                 <implementation> 
>                 ({getNumber: function(){
>                                 var a = counterInc (); 
>                                 a = a + "hhhh" + count;
>                                 return a;
>                 }, 
>  xblBindingsAttached: function(e){
>                                 alert(this.getInstanceNumber())
> }})
> </implementation>
> </binding>
> </xbl> 

Yes, that (modulo various unrelated issues) will work as you'd expect 
(incleasing the counter each time the binding is attached, however that 
happens).


> If I can do the above, then it might be good to state in section 3.5 
> that the script element is firstly evaluated and made available to 
> bindings.

The <xbl:script> is evaluated when it is inserted into a document, not 
when a binding is attached.

-- 
Ian Hickson               U+1047E                )\._.,--....,'``.    fL
http://ln.hixie.ch/       U+263A                /,   _.. \   _\  ;`._ ,.
Things that are impossible just take longer.   `._.-(,_..'--(,_..'`-.;.'

Received on Monday, 8 January 2007 02:26:25 UTC